I have a VBA-code which runs a batch file (bat file). The code runs without error when I run the batch file directly, and I get the correct result:
<code style="margin: 0px; padding: 0px; border: 0px; font-family: Consolas, Menlo, Monaco, 'Lucida Console', 'Liberation Mono', 'DejaVu Sans Mono', 'Bitstream Vera Sans Mono', 'Courier New', monospace, sans-serif; white-space: inherit;">Public Sub RunSASCodeViaBatFile()
Dim cmdString As String: cmdString = batPath & batFile & " " & SASFilePath & " " & SASFile & " " & SASOutputPath & " " & YearMonth
Dim wsh As Object
Set wsh = VBA.CreateObject("WScript.Shell")
Dim waitOnReturn As Boolean: waitOnReturn = True
Dim windowStyle As Integer: windowStyle = 2
wsh.Run cmdString, windowStyle, waitOnReturn
End Sub</code>However, when I try to run the script with an error check method like below, then the message box gives a message like:
Dim cmdString As String: cmdString = batPath & batFile & " " & SASFilePath & " " & SASFile & " " & SASOutputPath & " " & YearMonth
Dim wsh As Object
Set wsh = VBA.CreateObject("WScript.Shell")
Dim waitOnReturn As Boolean: waitOnReturn = True
Dim windowStyle As Integer: windowStyle = 2
Dim errorCode As Integer
errorCode = wsh.Run(cmdString, windowStyle, waitOnReturn)
If errorCode <> 0 Then
MsgBox "Program exited with error code " & errorCode & "."
End If
End Sub</code>I get that message, but I also get "the correct result" as I want in anyway. So it seems like that if-loop gives that message in anyway. It is a bit difficult to understand, because I have seen many other other people who used the same method.
<code style="margin: 0px; padding: 0px; border: 0px; font-family: Consolas, Menlo, Monaco, 'Lucida Console', 'Liberation Mono', 'DejaVu Sans Mono', 'Bitstream Vera Sans Mono', 'Courier New', monospace, sans-serif; white-space: inherit;">Public Sub RunSASCodeViaBatFile()
Dim cmdString As String: cmdString = batPath & batFile & " " & SASFilePath & " " & SASFile & " " & SASOutputPath & " " & YearMonth
Dim wsh As Object
Set wsh = VBA.CreateObject("WScript.Shell")
Dim waitOnReturn As Boolean: waitOnReturn = True
Dim windowStyle As Integer: windowStyle = 2
wsh.Run cmdString, windowStyle, waitOnReturn
End Sub</code>However, when I try to run the script with an error check method like below, then the message box gives a message like:
Program exited with error code 1001
<code style="margin: 0px; padding: 0px; border: 0px; font-family: Consolas, Menlo, Monaco, 'Lucida Console', 'Liberation Mono', 'DejaVu Sans Mono', 'Bitstream Vera Sans Mono', 'Courier New', monospace, sans-serif; white-space: inherit;">Public Sub RunSASCodeViaBatFile()
Dim cmdString As String: cmdString = batPath & batFile & " " & SASFilePath & " " & SASFile & " " & SASOutputPath & " " & YearMonth
Dim wsh As Object
Set wsh = VBA.CreateObject("WScript.Shell")
Dim waitOnReturn As Boolean: waitOnReturn = True
Dim windowStyle As Integer: windowStyle = 2
Dim errorCode As Integer
errorCode = wsh.Run(cmdString, windowStyle, waitOnReturn)
If errorCode <> 0 Then
MsgBox "Program exited with error code " & errorCode & "."
End If
End Sub</code>I get that message, but I also get "the correct result" as I want in anyway. So it seems like that if-loop gives that message in anyway. It is a bit difficult to understand, because I have seen many other other people who used the same method.