Option Compare Database Option Explicit Private Const PROCESS_QUERY_INFORMATION As Long = &H400 'プロセスの状態を取得する Private Const STILL_ACTIVE As Long = &H103 'プロセスは実行中である Private Declare Function CloseHandle Lib "kernel32" (ByVal hObject As Long) As Long Private Declare Function GetExitCodeProcess Lib "kernel32" (ByVal hProcess As Long, lpExitCode As Long) As Long Private Declare Function OpenProcess Lib "kernel32" (ByVal dwDesiredAccess As Long, ByVal bInheritHandle As Long, ByVal dwProcessId As Long) As Long Private Sub 実行_Click() Dim ProcessID As Long Dim ProcessHandle As Long Dim ExitCode As Long MsgBox "メモ帳を実行します。" ProcessID = Shell("notepad.exe", vbNormalFocus) ProcessHandle = OpenProcess(PROCESS_QUERY_INFORMATION, False, ProcessID) Do GetExitCodeProcess ProcessHandle, ExitCode DoEvents Loop While ExitCode = STILL_ACTIVE Call CloseHandle(ProcessHandle) MsgBox "メモ帳は終了しました。" End Sub