Automation Error: SHDocVw.InternetExplorer

MikeJoel
02-18-2008, 05:14 PM
I am starting out with http://www.xtremevbtalk.com/showthread.php?t=30761&highlight=Internet+Explorer

I declare,
Dim WithEvents IEObj As SHDocVw.InternetExplorer
Dim WithEvents SWObj As SHDocVw.ShellWindows

Then I use the "For Each" loop to find the window that has focus (also making sure it is actually a browser and not explorer),

'Create the Obj object of IE
Dim Obj As SHDocVw.InternetExplorer

'Loop through and find the window that has the
'current focus
For Each Obj In SWObj

If (Obj.hWnd = GetForegroundWindow) Then

If (InStr(1, Trim(LCase(Obj.FullName)), "iexplore.exe", vbTextCompare) > 0) Then
CurrentFocusWindow = Obj.LocationURL

If (CurrentFocusWindow <> LastFocusWindow) Then
UpdateBrowserObjects Obj
Exit For
End If

End If

End If

Next

'Clear the Obj
Set Obj = Nothing

(CurrentFocusWindow and LastFocusWindow are used to make sure the focus is changing to a different control, the CurrentFocusWindow is set to the obj.locationURL of the window with the current focus. While LastFocusWindow is set only when the app successfully changes to a browser)

Now, as you see if everything is right then I pass Obj through the sub UpdateBrowserObjects....


Public Sub UpdateBrowserObjects(Obj As InternetExplorer)
tmrCheckWindowFocus.Enabled = False

If (Obj.hWnd = GetForegroundWindow) Then

' Set the WebDoc conrol so we can control the page
' Set mhtmDoc3 = Nothing
' Set WebDoc = Nothing
Set mhtmDoc3 = Obj.document
Set WebDoc = mhtmDoc3

Set IEObj = Obj

LastFocusWindow = Obj.LocationURL
' Stop
Beep
Text2.Text = WebDoc.location
' Exit For
End If

'Next

Set Obj = Nothing

tmrCheckWindowFocus.Enabled = True

End Sub

(sorry for the commenting out of a lot of stuff, I have been trying to fix it)

(just ignore the Set mhtmDoc3 = Obj.document, Set WebDoc = mhtmDoc3, I am using that to give me access to the documents and events)

Now comes where it errors....
If I have two or more browsers open before the app starts I can switch between them fine. But if I close any of them, or open a new one I get an
Automation Error at
Set IEObj = Obj above in the UpdateBrowserObjects sub.


Why is this, any ideas

Thanks for any help
Mike

MikeJoel
02-18-2008, 09:19 PM
Error is: Run-time error '-2147023174 (800706ba)': Automation Error

I put the Set IEObj = Nothing in the OnQuit sub for IEobj and it seems to have helped alot...
But not I get the error what seems like randomly.
It always errors on the Set IEObj = Obj...
Obj seems to return nothing at these times.

nop90
05-18-2009, 02:24 AM
Hi Mike,

You should stop the process before leaving.

Obj.stop
Obj.quit

The webbrowser need to be stop b&#233;fore leaving.

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum