jhoward0101
New Member
- Joined
- Jan 7, 2017
- Messages
- 15
Hello. I am hoping to get some help to execute python code via VBA rather than executing a command batch file. I believe the reason the .py file is not executing because pathing in incorrect.
Here is the batch file that works:
C:
cd C:\users\Jim Howard\Desktop\TDDevelopment
path = %path%;%SystemRoot%\system32;%SystemRoot%;%SystemRoot%\System32\Wbem;%SYSTEMROOT%\System32\WindowsPowerShell\v1.0\;C:\TDApp;C:\Users\anaconda;C:\Users\anaconda\scripts;C:\Users\anaconda\Library\mingw-w64\bin;C:\Users\anaconda\Library\usr\bin;C:\Users\anaconda\Library\bin;C:\Users\anaconda\bin;C:\Users\anaconda\condabin;C:\Users\anaconda\Lib\site-packages\future\moves
erase status.txt
erase query.txt
python ordersquery.py
exit
and here is a short VBA module I am trying to use:
Sub RunPython()
Dim shell As Object
Dim exePath, scriptPath As String
Set shell = VBA.CreateObject("Wscript.shell")
spath = Environ$("systemroot\System32\" & ";" & "systemroot\System32\Wbem" & ";" & "systemroot\System32\WindowsPowerShell\v1.0\" & ";C:\TDApp;C:\Users\anaconda;C:\Users\anaconda\scripts;C:\Users\anaconda\Library\mingw-w64\bin;C:\Users\anaconda\Library\usr\bin;C:\Users\anaconda\Library\bin;C:\Users\anaconda\bin;C:\Users\anaconda\condabin;C:\Users\anaconda\Lib\site-packages\future\moves")
exePath = """C:\Users\Jim Howard\python.exe"""
scriptPath = "C:\Desktop\Tddevelopment\ordersquery.py"
shell.Run exePath & scriptPath
End Sub
I left the commented spath statement in to see what I have tried but it does not execute the .py flle, it also does not fail with an error, so I think if i could get the pathing right, it would work. I think python is being executed from anaconda with the batch file.
Any help would be much appreciated.
Thanks in advance,
James Howard
Here is the batch file that works:
C:
cd C:\users\Jim Howard\Desktop\TDDevelopment
path = %path%;%SystemRoot%\system32;%SystemRoot%;%SystemRoot%\System32\Wbem;%SYSTEMROOT%\System32\WindowsPowerShell\v1.0\;C:\TDApp;C:\Users\anaconda;C:\Users\anaconda\scripts;C:\Users\anaconda\Library\mingw-w64\bin;C:\Users\anaconda\Library\usr\bin;C:\Users\anaconda\Library\bin;C:\Users\anaconda\bin;C:\Users\anaconda\condabin;C:\Users\anaconda\Lib\site-packages\future\moves
erase status.txt
erase query.txt
python ordersquery.py
exit
and here is a short VBA module I am trying to use:
Sub RunPython()
Dim shell As Object
Dim exePath, scriptPath As String
Set shell = VBA.CreateObject("Wscript.shell")
spath = Environ$("systemroot\System32\" & ";" & "systemroot\System32\Wbem" & ";" & "systemroot\System32\WindowsPowerShell\v1.0\" & ";C:\TDApp;C:\Users\anaconda;C:\Users\anaconda\scripts;C:\Users\anaconda\Library\mingw-w64\bin;C:\Users\anaconda\Library\usr\bin;C:\Users\anaconda\Library\bin;C:\Users\anaconda\bin;C:\Users\anaconda\condabin;C:\Users\anaconda\Lib\site-packages\future\moves")
exePath = """C:\Users\Jim Howard\python.exe"""
scriptPath = "C:\Desktop\Tddevelopment\ordersquery.py"
shell.Run exePath & scriptPath
End Sub
I left the commented spath statement in to see what I have tried but it does not execute the .py flle, it also does not fail with an error, so I think if i could get the pathing right, it would work. I think python is being executed from anaconda with the batch file.
Any help would be much appreciated.
Thanks in advance,
James Howard