0
Good afternoon, I have a VBA command calling a specific Python script. What happens is that if I run the script manually, it works perfectly, no problem at all. Running by VBA it only gives the first Print command and nothing else.
VBA code:
Sub RunPython()
Dim PythonScript As String
Dim args As String
Dim wsh As Object: Set wsh = VBA.CreateObject("WScript.Shell")
PythonScript = """C:\Users\lgfrota\Desktop\Teste\StaticTest2.py"""
args = "C:\Python27\Lib\idlelib\idle.py"
Shell "C:\Python27\python.exe" & " " & args & " -r " & PythonScript
End Sub
Python code:
lista = []
for file
name in os.listdir('.'):
if ".dat" in filename:
lista.append(filename)
print filename
print lista
for i in range(len(lista)):
#Fazer coisas
print(ag,fx,fy,fz,mx,my,mz)
resultsnam = [ag, fx, fy, fz, mx, my, mz]
for rnam in resultsnam:
file.write(rnam.center(19, " ")+"|")
file.write("\n"*3)
Remembering that the file works perfectly when run separately.
Obs: The Filename print works but run manually it responds all the correct files of the folder. Running by vba, the answer is:
Custom Office Templates
desktop.ini
My Music
My Pictures
My Videos
Your VBA is starting python in your user’s folder
C:\Users\lgfrota\Documents
, and there is no file.dat
– nosklo
Even running the script in a folder that has this . dat? When I played the full path in python, it apparently worked perfectly. I’m trying to solve now, the way to make python get the filepath as argument delivered by VBA
– Luiz Frota
The folder where the script is not important; What matters is the folder that the VBA is considering as "current".
– nosklo