0

I have an input file in Excel which is used in a Python script solver.py. When I run the Python script, the outputs are printed in a different .xlsx file. I want to call the python script directly from the input file. I use the following code:

Dim objShell As Object
Dim PythonExe, PythonScript As String
Set objShell = VBA.CreateObject("Wscript.Shell")   

PythonExe = "C:*PATH*\Anaconda3\python.exe"
PythonScript = "C:*OTHERPATH*\solver.py"

objShell.Exec PythonExe & " " & PythonScript

ActiveWorkbook.UpdateLink Name:= _
        "C:*OTHERPATH*\output.xlsx", Type:= _
        xlExcelLinks

The last line is irrelevant, but when I manually change the output file and call the code, the values are updated. So I know for sure that this code runs completely. However, solver.py is never called. I see the black screen flashing shortly, but that's it, no calculations are made.

Why is solver.py not called? Is there any way to check what goes wrong, since I get no error messages?

3
  • Are you sure that user has access to the path under `C:` drive? Commented Jun 17, 2021 at 10:02
  • @MaciejLos These are my own files. I can open the python.exe manually. The files solver.py, output.xlsx and input.xslx with the VBA code are in the same folder. So I'm pretty sure the access isn't the problem? Commented Jun 17, 2021 at 10:06
  • I'd suggest to add error handler in your VBA code to find out what is causing the problem. Commented Jun 17, 2021 at 10:09

1 Answer 1

1

Found the answer myself. I ran the following in the command prompt:

"C:*PATH*\Anaconda3\python.exe" "C:*OTHERPATH*\solver.py" 

I found out that there were issues with importing pandas since numpy did not have the correct version. Running from within Spyder did not have this problem. Reinstalling both pandas and numpy fixed my problem.

Sign up to request clarification or add additional context in comments.

1 Comment

You made my day man! Thanks for the hint! I had the same issue too from excel, I'll remember to install pandas separately from now on!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.