January 25th, 2013, 03:07 AM
Execute a Python Script from Excel
I was not sure if this belonged in this forum - so apologies if I have posted in the wrong area.
I have a Python script which works perfectly and execeutes when I double click in Windows Explorer. I would like to execute the script when I click a button in my Excel spreadsheet.
In my Excel VBA I have used the following command:-
Call Shell(pyPath & pyFile)
pypath ="C:\Python26\python.exe "
However, when the code runs I can see the Python icon flash up in my task bar but the script does not run/execute, if I exclude the 'pyFile', the Python interface opens. Can you please tell me where I am going wrong?
January 25th, 2013, 08:56 AM
You might not be doing anything wrong. Have your python program exhibit a lasting external symptom.
time.sleep(8) # hold the window open for a few seconds
with open('a_sign.txt','w') as o:
[/code] are essential for python code and Makefiles!
January 28th, 2013, 03:56 AM
Thank you for the reply - I used the code and when I execute my VB script all I see is a 'black' python screen and the script does not execute. The strange thing is that it appears to be an intermittent issue - sometimes the script works and other times it doesn't, but I cannot find where the issue lies as I am not making any changes to the VB or Python scripts.
Originally Posted by b49P23TIvg
February 8th, 2013, 01:03 AM
Apply this VBA code to your folders and files. It worked for
me using Excel 2003.
Private Sub CommandButton1_Click()
Dim pyPrgm As String, pyScript As String
pyPrgm = "C:\Python33\python.exe "
pyScript = "C:\Python33\MyScripts\test1.py"
Call Shell(pyPrgm & pyScript, vbMaximizedFocus)