run bat file from vb

JeffGrant

Well-known Member
Joined
Apr 7, 2021
Messages
516
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 can you turn a range sideways?
Copy the range. Select a blank cell. Right-click, Paste Special, then choose Transpose.
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,215,110
Messages
6,123,146
Members
449,098
Latest member
Doanvanhieu

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