The following code launches internet explorer on the google webpage. Then a routine confirms that the IE windows was opened AND found.
This code will work ONLY if I toggle a breakpoint in the proLaunchIE procedure. I can simply CTRL-BREAK into code, then press F5 and it'll find the "google" IE window. But won't find it without user interaction. It will simply end the loop without finding IE. I think this is weird. Anyone with an idea what is causing that?Code:Call proLaunchIE Public Sub proLaunchIE() Shell "C:\Program Files\Internet Explorer\IEXPLORE.EXE www.google.com", vbMaximizedFocus Dim booIEWasFound As Boolean For i = 0 To 20 If fctIEHasFinishedLoading("Google") = True Then 'loading SUCCESSFUL booIEWasFound = True Exit For End If Next i If booIEWasFound = False Then MsgBox "String 'google' not found" Exit Sub End If End Sub Public Function fctIEHasFinishedLoading(strWindowCaption As String) As Boolean Dim strWindowCaptionFound As String Call proWaitWithSleep(1000) strWindowCaptionFound = (GetCaption$(DLHFindWin&(frmForm, strWindowCaption, False))) If strWindowCaptionFound <> "" Then fctIEHasFinishedLoading = True Else Debug.Print "window-caption not found" End If End Function Public Function GetCaption(lhWnd As Long) As String Dim sA As String, lLen As Long lLen& = GetWindowTextLength(lhWnd&) sA$ = String(lLen&, 0&) Call GetWindowText(lhWnd&, sA$, lLen& + 1) GetCaption$ = sA$ DoEvents End Function Public Function DLHFindWin(frm As Form, WinTitle As String, _ CaseSensitive As Boolean) As Long Dim lhWnd As Long, sA As String lhWnd& = frm.hwnd Do DoEvents If lhWnd& = 0 Then Exit Do If CaseSensitive = False Then sA$ = LCase$(GetCaption(lhWnd&)) WinTitle$ = LCase$(WinTitle$) Else sA$ = GetCaption(lhWnd&) End If If InStr(sA$, WinTitle$) Then DLHFindWin& = lhWnd& Exit Do Else DLHFindWin& = 0 End If lhWnd& = GetNextWindow(lhWnd&, 2) Loop End Function Public Function EnumProc(ByVal hwnd As Long, ByVal lParam As Long) As Boolean Dim sClass As String * 255 Call GetClassName(hwnd, sClass, 255) If Left(sClass, 4) = "Edit" Then hwndCONTROL = hwnd Exit Function 'the first "edit" field found is the one I need - I can quit function End If EnumProc = hwnd End Function
Tried putting "DoEvents" here and there but it didn't help.
Thank you!




Reply With Quote