So I have the following function that works great:
Public Sub ShellAndWait(ByVal program_name As String, _ Optional ByVal window_style As VbAppWinStyle = vbNormalFocus, _ Optional ByVal max_wait_seconds As Long = 0) Dim lngProcessId As Long Dim lngProcessHandle As Long Dim datStartTime As Date Dim lngCursor As Long Const WAIT_TIMEOUT = &H102 Const SYNCHRONIZE As Long = &H100000 Const INFINITE As Long = &HFFFFFFFF lngCursor = Screen.MousePointer 'Screen.'MousePointer = vbHourglass ' Start the program. On Error GoTo ShellError lngProcessId = Shell(program_name, window_style) On Error GoTo 0 DoEvents ' Wait for the program to finish. ' Get the process handle. lngProcessHandle = OpenProcess(SYNCHRONIZE, 0, lngProcessId) If lngProcessHandle <> 0 Then datStartTime = Now Do If WaitForSingleObject(lngProcessHandle, 250) <> WAIT_TIMEOUT Then Exit Do End If DoEvents If max_wait_seconds > 0 Then If DateDiff("s", datStartTime, Now) > max_wait_seconds Then Exit Do End If Loop CloseHandle lngProcessHandle End If Screen.MousePointer = lngCursor Exit SubShellError:End Sub
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:37:38:39:40:41:42:
Select All Code
I would like to change it so that it does the same thing but doesn't wait for the process to finish. I still want it to finish, but in the background.
Any ideas?