I am just starting to learn Internet Explorer Automation using VBA and I am facing an issue.
The Document object is empty which prevents me from going further than just loading a page. I have been looking around the net for a solution to this and could not find anything working so here I am, asking for your help.
NB: My VBA level is intermediate
Windows 8.1 pro 64 bit
I wrote an example code
I had a the same issue (nothing in the .document) , with Internet Explorer 11.
I had to add the site to the Compatibility View list (gear, compatibility view, add)
Hopefully this will help someone avoid the time I spent looking for a solution.
This code works for me. It uses a loop to wait until navigation is complete.
Sub NavigateGoogle()
Dim i As Long
Dim ie As InternetExplorer
Dim Googledoc As HTMLDocument
Set ie = CreateObject("InternetExplorer.Application")
ie.Visible = True
ie.navigate "www.google.com"
Do
DoEvents
Loop While ie.Busy
Set Googledoc = ie.document
Debug.Print Googledoc.all(0).innerHTML
Set ie = Nothing
End Sub
Related
I have managed to get my code to work, but only by searching the internet and finding something that worked, I don't actually understand why.
Could someone please explain why when I used
Dim IE As New InternetExplorer
trying to press a button gave me the error
Object invoked has disconnected from clients
but using
Dim ie As SHDocVw.InternetExplorer
has worked?
Thank You
You are trying to do early binding of IE in VBA. Thus, you need to do it like this:
Dim ie As SHDocVw.InternetExplorer or Dim IE As New InternetExplorer, after adding the "Microsoft Internet Controls" library to the project (c:\windows\syswow64\ieframe.dll).
In general, if you want to do late binding, you should do it like this:
Dim IE As Object
Set IE = CreateObject("InternetExplorer.Application")
What is the difference between Early and Late Binding? and my understanding about late and early binding
I am trying to automate a process of downloading file from a website. At the moment I am able to open a link that runs a javascript which produces an output file, here's my code:
Sub WebDataExtraction()
Dim URL As String
Dim IeApp As Object
URL = "http://si3.bcentral.cl/Siete/secure/cuadros/DescargarExcel.aspx?DropDownListFrequency=&DrDwnCalculo=NONE&codCuadro=UF_IVP_DIARIO"
Set IeApp = CreateObject("InternetExplorer.Application")
IeApp.Navigate URL
End Sub
When I run the sub the IE View Downloads window pops out. To download the file I am trying to follow this approach, however while I am using the attached code I am unable to find a child window.
Can somebody advise me how to proceed from here? Or maybe any suggestion how to approach this problem differently?
I am currently using Office 2010, Visual Basic for Applications 7, and Internet Explorer 9.
The current issue I've been having is that using an IE object seems to fail on our intranet, and I was wondering if there was a fix for this.
Functioning code:
Dim IE As Object
Set IE = CreateObject("InternetExplorer.Application")
IE.Navigate "http://www.google.com"
WaitUntilReady IE
'Application.Wait (Now + TimeValue("00:00:10"))
'IE.Visible = True
MsgBox (IE.Document.body.innerHTML)
Broken code:
Dim IE As Object
Set IE = CreateObject("InternetExplorer.Application")
IE.Navigate "http://intranet/"
WaitUntilReady IE
'Application.Wait (Now + TimeValue("00:00:10"))
'IE.Visible = True
MsgBox (IE.Document.body.innerHTML)
Functioning code does exactly what it should. Makes an IE object which doesn't show up visibly on screen, and returns a message box with the HTML code contents of google.com
Broken code loads our intranet home page, in a VISIBLE IE window, and returns this error:
Run-time error '-2147417848 (80010108)'
Automation error
The object invoked has disconnected from its clients
I've read through Excel VBA Controlling IE local intranet which suggested using an IP address instead of intranet/ which doesn't work because the IP directs to a different splash screen.
I've also tried using
Set IE = New InternetExplorerMedium
But this A- didn't seem to work either, and B- would mean making sure all my fellow employees enable this Reference.
Also, I've tried loading google.com first, then having it navigate to intranet/, which also didn't help.
Anyone have any suggestions? From my understanding, loading intranet/ is causing IE to disconnect from Excel somehow?
SO! After several days of research and at a complete loss for what was going on, I stumbled on to someone talking about intranet compatibility mode in another article.
Force "Internet Explorer 8" browser mode in intranet
Things happened to click in my head when I read this, realizing that if IE loaded in compatibility, it would explain why the Excel VBA macro lost control of IE, as compatibility mode might be loading as a separate instance of IE.
Settings > Internet Options > Security > Local Intranet > Sites >
Disable "Auto detect intranet" and enable "Include all network paths (UNCs)" fixes the error I was having, perfectly.
'simply replace -seem to work
' Set ie = CreateObject("InternetExplorer.Application")
Set ie = New InternetExplorerMedium
another solution
Set IE = CreateObject("InternetExplorer.Application")
IE.Navigate ("http://URLOnMyIntranet/site.html")
IE.Visible = True
Set IE = nothing
Set objShellApp = CreateObject("Shell.Application")
For Each objWindow In objShellApp.Windows
Debug.Print objWindow.LocationName
If LCase(objWindow.LocationName) = LCase("Your windows name, use debug to find out") Then
Set IE = objWindow
End If
Next`enter code here`
also see this post
I get two different errors on the same line. Sometimes this one:
Automation error: object invoked has disconnected from its clients
and sometimes:
the interface is unknown
Minimal code to reproduce error:
Sub mcve()
Dim ie As Object
Dim www As String
Set ie = New InternetExplorerMedium
www = "http://www.stackoverflow.com"
ie.navigate www
ie.Visible = False
While ie.ReadyState <> 4 ' <~~~~~~~~~~~~~~~~~~~~~~~~ Error occurs here
DoEvents
Wend
End Sub
This requires a reference: Tools > References... > Microsoft Internet Controls
The error occurs on While ie.ReadyState <> 4 the second time. How do I fix this?
This is a duplicate of a previously asked question. The problem seems to be caused by Internet Explorer security settings - when switching between security zones, the current instance of IE is killed and a new instance is created, so your reference to the old process is no longer valid.
Some of the suggested solutions were:
Change IE security settings. Uncheck "enable protected mode" on the Security tab of Internet Options.
Navigate to the IP address directly instead of the URL. This is the one that fixed it for me. For example, ie.navigate "64.233.177.106" (Google's IP address)
Set ie = New InternetExplorerMedium instead of New InternetExplorer. Or in your case, vice versa.
Instead of
Set ie = New InternetExplorerMedium
just use
Set ie = New InternetExplorer
or, for late binding:
Set ie = CreateObject("InternetExplorer.Application")
This makes the error go away.
I'm not sure why you would use InternetExplorerMedium in the first place. Quoting the small print in the documentation:
Remarks
Windows Internet Explorer 8. On Windows Vista, to create an instance of Internet Explorer running at a medium integrity level, pass CLSID_InternetExplorerMedium (defined in exdisp.idl) to CoCreateInstance. The resulting InternetExplorerMedium object supports the same events, methods, and properties as the InternetExplorer object.
Are you really using IE8 on Windows Vista, and do you really want "medium integrity level", whatever that means? I didn't think so.
Open Internet Explorer, then, go to internet settings, open "Sites" ande clear the web page that need the server comprobation. The problema is for the server comprobation.
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 "http://en.wikipedia.org/wiki/Visual_Basic"
wait ie
Debug.Print "Current URL: " & ie.LocationURL
ie.Navigate "http://en.wikipedia.org/wiki/Microsoft_Office"
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?
Update: I couldn't find a solution, so I went for the workaround of opening a new IE window for each URL.
I am not familiar with the VBA IE automation that you are using, however it sounds like you are hitting the same issue as Selenium WebDriver on IE11.
You may need to follow the same steps provided by the in the Selenium Wiki.
For IE 11 only, you will need to set a registry entry on the target
computer so that the driver can maintain a connection to the instance
of Internet Explorer it creates. For 32-bit Windows installations, the
key you must examine in the registry editor is
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Internet
Explorer\Main\FeatureControl\FEATURE_BFCACHE. For 64-bit Windows
installations, the key is
HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\Internet
Explorer\Main\FeatureControl\FEATURE_BFCACHE. Please note that the
FEATURE_BFCACHE subkey may or may not be present, and should be
created if it is not present. Important: Inside this key, create a
DWORD value named iexplore.exe with the value of 0.
http://code.google.com/p/selenium/wiki/InternetExplorerDriver
Hopefully that fixes your problem!
THX, You helped me.
W7 Ultimate 64bit czech, IE11, VBA in Microstation V8i
I use code like:
Public explorer As Object
....
Set explorer = CreateObject("InternetExplorer.Application")
....
If InStr(explorer.LocationURL, "CAPTCHA") = 0 Then
...
End If