I am using the following VBA code to run a bat file. It was an example to run the note pad application instead of .bat file. While running I am getting an error "Method run of object ISshShell3 failed" Please let me know how can i use it to run the bat file from a desired directory? My aim is to run a command on console and wait for the command to finish.
Dim wsh As Object
Set wsh = VBA.CreateObject("WScript.Shell")
Dim waitOnReturn As Boolean: waitOnReturn = True
Dim windowStyle As Integer: windowStyle = 1
Dim errorCode As Long
errorCode = wsh.Run("D:\test.bat", windowStyle, waitOnReturn)
If errorCode = 0 Then
MsgBox "Done! No error to report."
Else
MsgBox "Program exited with error code " & errorCode & "."
End If
Thanks in advance
net usepausewsh.CurrentDirectory = exePath... I can't test this because I still can't replicate the error, even when running a batch file from a flash drive or network folder... which makes me think your Windows or XL version may be relevantwsh.Run("cmd.exe /C D:\test.bat", windowStyle, waitOnReturn)D:\myfolder\make.exeexists