等用Shell調用的程序執行完成后再執行其它程序(VBA)

来源:百度文库 编辑:神马文学网 时间:2024/06/13 01:16:24
Public Declare Function WaitForSingleObject Lib "kernel32" (ByVal hHandle As Long, ByVal dwMilliseconds As Long) As Long
Public Declare Function CloseHandle Lib "kernel32" (ByVal hObject As Long) As Long
Public Declare Function OpenProcess Lib "kernel32" (ByVal dwDesiredAccess As Long, ByVal bInheritHandle As Long, ByVal
dwProcessId As Long) As Long
Public Const INFINITE = -1&
Public Const SYNCHRONIZE = &H100000

Private Sub Command1_Click()
    Dim i As Long
    Dim r As Long
    Dim p As Long
    i = Shell("NOTEPAD.EXE", vbNormalFocus)
    p = OpenProcess(SYNCHRONIZE, False, i)
    r = WaitForSingleObject(p, INFINITE)
    r = CloseHandle(p)
    MsgBox "Program Close"
End Sub