Running a python script from a macro/command button

blimpy

New Member
Joined
Jan 10, 2014
Messages
1
I have been searching for a way to do this and came across the Shell() command. However no matter how I try I cannot get it to work. The python icon will flash up for a minute but the script does not run. This is what I have

Code:
Shell ("C:\Python27\python.exe ""C:\Python27\Scripts\weatherftpdownload.py")

I also tried this.. But it didn't work either.

Code:
pyPrgm = "C:\Python27\python.exe "

pyScript = "C:\Python27\Scripts\weatherftpdownload.py"
Call Shell(pyPrgm & pyScript)

I know nothing about Python and the python code was developed by someone else. It works fine when I double click the python file directly but I need to run it from excel somehow.... Any help appreciated...
 

Excel Facts

Excel Wisdom
Using a mouse in Excel is the work equivalent of wearing a lanyard when you first get to college
I found a trick to run a .py script using a .bat file/script

If you know how to make a .bat file ( open a txt file, put the code below.

in the .bat file, to run a .py script
the code is:
Change folder name and .py script name accordingly
Code:
@echo off


C:\folde_xyz\pythonscript123.py %*
Save the txt file with .bat at the end instead of txt.
Save As:
runmy pyscript.bat )

You can now simply clik on the new .bat file, and test run your.py script.
That's the first test.


Now, all you need to do is VBA to Run the .bat file, which will run the .py script.

I don't have a unique way, but many examples here, use the one that works
 
Upvote 0

Forum statistics

Threads
1,213,510
Messages
6,114,048
Members
448,543
Latest member
MartinLarkin

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top