Call Python Script From Vba
I'm having a problem calling python scripts from vba in Excel. I read other threads that addressed the same problem, but when I run the code, a Python screen flashes and then disap
Solution 1:
The screen flashes and returns quickly because the program either failed or ran that fast to completion
Have you tried to run it from the command line to see what is happening?
If that runs fine, you can force the command window to stay open so you can read what's happening when you use python from the Shell command
Call Shell("cmd.exe /S /K" & "C:\Users\opera\AppData\Local\Programs\Python\Python36\python.exe" & " " & args, vbNormalFocus)
/S Modifies the treatment of string after /C or /K
/C Carries out the command specified bystringand then terminates
/K Carries out the command specified bystring but remains
Solution 2:
I tried the below as suggested:
Dim RetVal
args = """C:\Users\something\Desktop\md\test.py"""
RetVal = Shell("C:\Python37\python.exe " & " " & args)
If RetVal = 0 Then
MsgBox "Couldn't run python script!", vbOKOnly
End If
After running the script the command window was just flashing. So, I just added input('Press any key to exit') statement as the last line of my python script and now the window stays.
Post a Comment for "Call Python Script From Vba"