Hey everyone, hope your having a great day!
I'm having some difficulty with a function I found called "ShellAndWaitReady" (http://www.visualbasic.happycodings....er/code38.html) but I can't seem to make it do what I want it to. Essentially what I need to happen is have MS Outlook be FULLY loaded before the rest of my code executes. Unfortunately, right now my code is continuing before the program loads and its messing things up. Does anyone have any suggestions? Thanks so much!
VB Code:
'Purpose : Holds execution until application has finished opening 'Inputs : sCommandLine = The Command line to run the application e.g. "Notepad.exe" ' lState = The Window State to run of the shelled program (A Long) 'Outputs : Returns the Process Handle 'Notes : Use this when you want to wait for an application to finishing opening before proceeding ' The side effects mentioned in ShellAndHold will be negligible since the most applications ' load in under 5 seconds. Function ShellAndWaitReady(sCommandLine As String, Optional lState As Long = vbNormalFocus) As Long Dim lhProc As Long If Left$(sCommandLine, 1) <> Chr(34) Then sCommandLine = Chr(34) & sCommandLine End If If Right$(sCommandLine, 1) <> Chr(34) Then sCommandLine = sCommandLine & Chr(34) End If lhProc = Shell(sCommandLine, lState) 'Wait for the process to initialize Call WaitForInputIdle(lhProc, INFINITE) 'Return the handle ShellAndWaitReady = lhProc End Function Private Sub cmdOutlook_Click() Dim fileName As String Dim retrunValue As Long fileName = "C:\Program Files\Microsoft Office\OFFICE\outlook.EXE" retrunValue = ShellAndWaitReady(fileName) 'FROM THIS POINT ON IS WHERE THE REST OF THE CODE IS EXECUTING End Sub




Reply With Quote