run bat file from vb

JeffGrant

Well-known Member
Joined
Apr 7, 2021
Messages
558
Office Version
  1. 365
Platform
  1. Windows
Hi All,

Just wondering why I can a run bat file from the command prompt, but when I run

Sub RunPYScript()

VBA Code:
Dim wsh As Object
Set wsh = VBA.CreateObject("WScript.Shell")
Dim waitOnReturn As Boolean: waitOnReturn = True
Dim windowStyle As Integer: windowStyle = 1
wsh.Run "C:\Users\jeff\Desktop\Betfair Bot\RUNPY.BAT", windowStyle, waitOnReturn
MsgBox "Wait for Data to Download"
End Sub


it gives me a runtime error

1697224081044.png


I do run other external programs direct using the EXECCMD command and that works file, but running a bat file is throwing me.

Any assistance greatly received.
 

Excel Facts

How to total the visible cells?
From the first blank cell below a filtered data set, press Alt+=. Instead of SUM, you will get SUBTOTAL(9,)
Try:
VBA Code:
    wsh.Run "cmd.exe /c ""C:\Users\jeff\Desktop\Betfair Bot\RUNPY.BAT""", windowStyle, waitOnReturn
 
Upvote 0
It's probably because WScript doesn't accept the space between Betfair Bot in your path, try instead:
VBA Code:
wsh.Run """C:\Users\jeff\Desktop\Betfair Bot\RUNPY.BAT""", WindowStyle, waitOnReturn

Ps. Hi to all.
 
Upvote 0
Thanks Folks...

It is just funny how the proverbial DOS rules still hang around. I figured it would be something simple like that.
 
Upvote 0

Forum statistics

Threads
1,224,820
Messages
6,181,160
Members
453,021
Latest member
Justyna P

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