PDA

View Full Version : Solved: Web page closes itself then opens a new IE... How can I track?



MattKlein
04-29-2008, 09:44 AM
Hi all!

I am having Excel pull some data from the web using CreateObject("InternetExplorer.Application"). However, one of the web pages I am trying to navigate to has IE close itself down, then open a new IE instance (so it can remove the address bar, toolbars, etc...). When this happens, my IE object pointer (sorry, not sure what its called in VB) is no longer valid. So my question is:

How can I re-grab the object pointer for this "new" IE window? (or prevent IE from closing down and forcing the web page to load in the current IE instance?)

Thank you all for your help!

akanchu
04-29-2008, 07:21 PM
Hi Matt,

if you know the title of the new window that opens and it does not match others then you could use the below code..

Dim IEhandle3 As InternetExplorer
Set IEhandle3 = CreateObject("InternetExplorer.Application")

Private Sub get_IE_handle()
Dim mywinie As Object
Set mywinie = CreateObject("Shell.application")
Dim allwindows As Object
Set allwindows = mywinie.Windows

For Each myie3 In allwindows
' Debug.Print myie3.LocationURL
If myie3.LocationURL = CRURL Then ' check for IE that has the required URL
Exit For
End If
Next
Set IEhandle3 = myie3
End Sub



Hope this helps.

MattKlein
04-30-2008, 07:29 AM
Thanks akanchu! That's exactly what I was looking for!