PDA

View Full Version : Internet Explorer automation not working with IE11



python_dude
08-27-2014, 02:20 AM
Hi everyone,

I have some code that retrieves data from multiple websites via Internet Explorer automation in VBA. My code worked without problems with IE8, but in IE11, after the Navigate method of the Internet Explorer object is called, the Document and LocationURL are not updated; they still refer to the previously displayed website. Here's some code to reproduce the problem:


Sub Test()
Debug.Print "start"
Dim ie
Set ie = CreateObject("InternetExplorer.Application")
ie.Visible = True
ie.Navigate url1
wait ie
Debug.Print "Current URL: " & ie.LocationURL
ie.Navigate url2
wait ie
Debug.Print "Current URL: " & ie.LocationURL
Set ie = Nothing
End Sub

Sub Wait(ie As Variant)
Do While ie.Busy
Application.wait DateAdd("s", 1, Now)
Loop
End Sub

When a run the above Test sub on a machine with IE8, it prints two different URLs, which is the expected behavior. However, when I run the same code on a machine with IE11, it prints the first URL twice. Any idea what might be wrong?

Note: To run the above code, you have to set two variables url1 and url2. The forum post rules didn't allow me to set those.

stanl
09-11-2014, 10:38 AM
Not sure if this helps, but IE11 has several new properties to allow navigation among tabs where more than one url is opened, or to not used cached html - example.



navOpenInNewWindow=1
navNoHistory=2
navNoReadFromCache=4
navNoWriteToCache=8
navAllowAutosearch=16
navBrowserBar=32
navHyperlink=64
navEnforceRestricted=128
navNewWindowsManaged=256
navUntrustedForDownload=512
navTrustedForActiveX=1024
navOpenInNewTab=2048
navOpenInBackgroundTab=4096
navKeepWordWheelText=8192
navVirtualTab=16384
navBlockRedirectsXDomain=32768
navOpenNewForegroundTab=65536
cURl = "myurl.com"
oIE= CreateObject("InternetExplorer.Application")
oIE.Visible=1
oIE.Navigate URL="myurl.com",Flags:=navNoReadFromCache

python_dude
09-11-2014, 10:58 AM
Thanks for the answer, although I already gave up on trying to get this to work. As a workaround, I simply opened a new IE window for each request, closing the previous window based on its title using the Windows API.

cholland3403
02-08-2016, 06:42 AM
I know this is an old thread, but thought I would post how I solved the problem. It takes a little longer to run the code, but does not require any API calls.

I first created a public sub that controls the navigation to the desired url.


Public Sub NavigateToPage(ByVal url As String, ByRef IE As Object) On Error GoTo SkipBrowse
IE.Navigate2 url
While IE.Busy
DoEvents
Wend
While IE.document.readyState <> "complete"
DoEvents
Wend
SkipBrowse:
End Sub

Then I call the sub (passing the url and the IE object) from the original routine and then check to see if the loaded url is the url specified. If not, I go back to a defined label and try again.


retry1:
Call NavigateToPage(someURL, IE)
If Not IE.LocationURL = someURL Then GoTo retry1



You may want to add a counter to limit the number of tries or something like that, but so far this has worked for me.