This “wait” routine suspends your code and waits for the shelled process to finish. It comes in handy when you need to run another scriptatch file during your process. Use this calling syntax:
Private sub cmdPrint_Click() WaitForProcessToEnd "C:PLOTTER.BAT" 'Let the user know when the process is finished. MsgBox "The process is finished! "End Sub
Here are the API declarations:
Public Const INFINITE = -1&Public Declare Function WaitForSingleObject _ Lib "kernel32" (ByVal hHandle As Long, _ ByVal dwMilliseconds As Long) As LongPublic Declare Function OpenProcess Lib _ "kernel32" (ByVal dwAccess As Long, _ ByVal fInherit As Integer, _ ByVal hObject As Long) As LongPublic Sub WaitForProcessToEnd(cmdLine As String) 'You can substitute a discrete time 'value in milliseconds for INFINITE. Dim retVal As Long, pID As Long, pHandle _ As Long pID = Shell(cmdLine) pHandle = OpenProcess(&H100000, True, pID) retVal = WaitForSingleObject(pHandle, INFINITE)End Sub