Declare Function WaitForSingleObject Lib "kernel32" (ByVal hHandle As Long, ByVal dwMilliseconds As Long) As Long
Declare Function OpenProcess Lib "kernel32" (ByVal dwDesiredAccess As Long, ByVal bInheritHandle As Long, ByVal dwProcessId As Long) As Long Public Const INFINITE = -1 Public Sub ShellWait(ByVal FileName As String, optional WindowStyle As Variant) Dim idProc As Long Dim hProc As Long ' start program and save PID idProc = VBA.Shell(FileName, WindowStyle) ' get process handle hProc = OpenProcess(PROCESS_ALL_ACCESS, False, idProc) 'wait till program has finished If hProc <> hNull Then Call WaitForSingleObject(hProc, INFINITE) Call CloseHandle(hProc) End If End Sub |