I'm want to run my python script from Excel VBA and this code works:
Dim newShell As Object
Dim PythonExePath As String, PythonScriptPath As String
Set newShell = VBA.CreateObject("Wscript.Shell")
PythonExePath = """C:\MyPythonPath\pythonw.exe"""
PythonScriptPath = """C:\MyScriptPath\anyscript.py"""
newShell.Run PythonExePath & PythonScriptPath`
I want to run it with high priority, so I tried in cmd.exe the next construction:
start /high "C:\MyPythonPath\pythonw.exe" "C:\MyScriptPath\anyscript.py"
and it works a little faster. So I want to use the same construction, when calling from Excel VBA, but I can't find a way how I should insert that "start /high" part. I tried many variations, but it still gives me an error "Run-time error '-2147024894 (80070002): Method "Run' of object 'IWshShell3' failed", which, as I understand, states, that it can't find the file.
So, please, show me the way to call it correctly. Among not working variants are, for example, these (especially if you want to make some fun of my ignorancy):
newShell.Run "start " & Chr(34) & Chr(34) & " /high " & PythonExePath & PythonScriptPath`
newShell.Run "start " & Chr(34) & Chr(34) & " /high " & PythonExePath & " " & PythonScriptPath
newShell.Run "/high " & PythonExePath & " " & PythonScriptPath
newShell.Run "start /high ""C:\MyPythonPath\pythonw.exe"" ""C:\MyScriptPath\anyscript.py"""
newShell.Exec ("start /high " & PythonExePath & " " & PythonScriptPath)
newShell.Exec ("start /high ""C:\MyPythonPath\pythonw.exe"" ""C:\MyScriptPath\anyscript.py""")
And some more. I've found some solutions to make the priority of the running process higher from inside the python code, but I would like to start it from VBA already with high priority — and on that I didn't find answers unfortunately, although spent several hours on it.