1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36
| #If VBA7 Then
Private Declare PtrSafe Function GetExitCodeProcess Lib "kernel32" ( _
ByVal hProcess As LongPtr, lpExitCode As Long) As Long
Private Declare PtrSafe Function OpenProcess Lib "kernel32" ( _
ByVal dwDesiredAccess As Long, ByVal bInheritHandle As Long, _
ByVal dwProcessID As Long) As LongPtr
Declare PtrSafe Function mciExecute Lib "winmm.dll" ( _
ByVal lpstrCommand As String) As Long
#Else
private Declare Function OpenProcess Lib "kernel32" (ByVal dwDesiredAccess As Long, ByVal bInheritHandle As Long, ByVal dwProcessId As Long) As Long
Private Declare Function GetExitCodeProcess Lib "kernel32" (ByVal hProcess As Long, lpExitCode As Long) As Long
Declare Function mciExecute Lib "winmm.dll" (ByVal lpstrCommand As String) As Long
#End If
Private Const STILL_ACTIVE = &H103
Private Const PROCESS_QUERY_INFORMATION = &H400
Public Sub ShellWait(ByVal JobToDo As String)
#If VBA7 Then
Dim hProcess As LongPtr
#Else
Dim hProcess As Long
#End If
Dim RetVal As Long
hProcess = OpenProcess(PROCESS_QUERY_INFORMATION, False, Shell(JobToDo, vbMinimizedNoFocus))
Do
GetExitCodeProcess hProcess, RetVal
DoEvents
Loop While RetVal = STILL_ACTIVE
End Sub
Public Sub TestApplication()
ShellWait "NOTEPAD.EXE"
MsgBox "Process Fini"
End Sub |