Answer the question
In order to leave comments, you need to log in
Why does an error occur when running a Python exe file through excel?
Hello everyone
There is such a strange error and I do not know what it can be connected with
I have an eskl file. I need to do different types of data processing in it and I wrote a python script. I call this script through vba. I choose the path through the file selection button. I write the path to the file in a cell, and then I access the cell and run the script.
The problem is that after closing the excel and restarting the computer, when I want to call my script again, I get an error
The most interesting thing is that if I redefine the path to the script, that is, I click on the button for selecting the path to the script, then everything will work ... Although the path is specified in the cells correctly ... no processes change the path. That is, the script itself is called, but an error is produced. And it seems like this error is due to the fact that the running script "sees itself" in the wrong folder where it is, but this is not accurate.
I don't understand how redefining the path in the cells treats this ...
If I defined the path to the script and again click on the path definition button, then it shows the path where the file lies.
If I restarted the computer and clicked again to define the path, then by default it offers me "my documents". And I somehow did the output of errors and once I managed to see that it seemed like the script was accessing "my documents", and not where the script is, when I used os.getcwd ()
Answer the question
In order to leave comments, you need to log in
Can your python script run with any current directory?
Maybe the current directory is not specified in the launch code, and the one that was last used in excel is used (when the file open dialog is called, as far as I know, the current directory changes)?
Set it before calling with WScriptShell.CurrentDirectory = "....."
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question