VBA or BAT won't run python script

32CARDS

Board Regular
Joined
Jan 1, 2005
Messages
123
I have some python scripts to run using VBA,
At first it worked, then stopped working after a PC change over.
( the old pc rip'd)
I thought it may be something in the VBA module Tools/References but not really sure what to look for.
Then I tried a test .bat file and still nothing happens.
Yet when I double click on the python script file on it's own it works OK,it does what it is suppose to do.
python version is 3.4 32 bit

Anything I may have overlooked to have py scripts working through VBA again ?
Syntax currently in VBA is:
Code:
Shell "C:\\Python34\\python.exe c:\\C:\FolderTesting\\testscript.py"

Thanks
 

Excel Facts

Shade all formula cells
To shade all formula cells: Home, Find & Select, Formulas to select all formulas. Then apply a light fill color.
Re: VBA or BAT won't run python script--SOLVED

Code:
Option Explicit

Sub test()


  Dim PathCrnt As String

    ChDir "C:\directory_bat_is_in "

  PathCrnt = ActiveWorkbook.Path

  Call Shell(PathCrnt & "\name_of_batfile.BAT " & PathCrnt)

End Sub
 
Upvote 0
Syntax currently in VBA is:
Code:
Shell "C:\\Python34\\python.exe c:\\C:\FolderTesting\\testscript.py"
Why are you using double backslashes? VB, as well as Windows, uses single backslashes between path elements. See if changing all the \\ to \ works for you.
 
Upvote 0
Why are you using double backslashes? VB, as well as Windows, uses single backslashes between path elements. See if changing all the \\ to \ works for you.

Thank for the reply MrExcel,
Yes I tried various combinations. The double backslash was suggested by the author of the py scripts, but had not tested it themselves, it was up to me.
I thought at first everything was OK, when I simply clicked on the py scripts at first, and said back, "yep, all good", an error on my part.
When I constructed the project, tried to fire the scripts in the Run of things,
nada.
Then simply searched and searched, it made sense to use bat with a dynamic folder reference. It worked. I "see" it now, this part here forces the machine to make a "direction change" ? I think;
Code:
ChDir "C:\
 
Upvote 0

Forum statistics

Threads
1,214,583
Messages
6,120,377
Members
448,955
Latest member
BatCoder

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