Amar
Amar

Reputation: 81

Automation error when getting ReadyState of InternetExplorer object

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?

Upvotes: 8

Views: 29586

Answers (3)

user12806112
user12806112

Reputation: 1

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.

Upvotes: 0

Elizabeth Amato
Elizabeth Amato

Reputation: 481

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:

  1. Change IE security settings. Uncheck "enable protected mode" on the Security tab of Internet Options.
  2. 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)
  3. Set ie = New InternetExplorerMedium instead of New InternetExplorer. Or in your case, vice versa.

Upvotes: 5

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.

Upvotes: 4

Related Questions