I have some VBA code that calls on VBScript code to run an SAP export:
'**VBA CODE 'Grab date modified before running export tstamp = FileDateTime("exportFilePath") 'Call .vbs file for SAP export and pass shift variable to .vbs file Shell "wscript """ & "filepath.vbs" & Shift & " " & DateOffset, vbNormalFocus 'Wait for export file to update before opening X = 1 newtstamp = FileDateTime("exportFilePath") Do While tstamp = newtstamp Application.Wait (Now TimeValue("0:00:01")) newtstamp = FileDateTime("exportFilePath") X = X 1 If X = 60 Then 'allow 60 seconds for export 1 to complete before exiting script MsgBox ("Export 1 took over 60 seconds and failed to complete, try again!") Exit Sub End If Loop
In certain cases, the VBScript will be ended early (user not signed into SAP, etc.)
'**VBScript On Error Resume Next Set SapGuiAuto = GetObject("SAPGUI") Set SAPApp = SapGuiAuto.GetScriptingEngine Set SAPCon = SAPApp.Children(0) Set session = SAPCon.Children(0) If Err.Number <> 0 Then 'Error number of zero means no error MsgBox ("Error! Log into SAP then try again.") wscript.Quit End If
In cases like this, I would like to be able to communicate to VBA that the VBScript ended early. Doing this would allow the VBA code to end before the allotted 60 seconds built into the Do Loop.
Thoughts and suggestions??