Automation error while getting ReadyState of InternetExplorer

I get two different errors on the same line. Sometimes it is:

Automation error: the called object disconnected from its clients

and sometimes:

interface unknown

Minimum code to reproduce the 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 link: Tools> Links ...> Microsoft Internet Controls

The second time the error occurs on While ie.ReadyState <> 4 . How to fix it?

+5
source share
2 answers

This is a duplicate of a previously asked question. The problem is related to Internet Explorer security settings - when switching between security zones, the current IE instance is killed and a new instance is created, so your link to the old process is no longer valid.

Some of the suggested solutions are:

  • Change IE security settings. Uncheck "enable protected mode" on the "Security" tab in the "Internet Options" section.
  • Go directly to the IP address instead of the URL. This is the one that fixed it for me. For example, ie.navigate "64.233.177.106" (Google IP)
  • Set ie = New InternetExplorerMedium instead of New InternetExplorer . Or in your case, vice versa.
+4
source

Instead

 Set ie = New InternetExplorerMedium 

just use

 Set ie = New InternetExplorer 

or, for late binding:

 Set ie = CreateObject("InternetExplorer.Application") 

This will result in an error.

I'm not sure why you would use InternetExplorerMedium in the first place. Quoting a small print in the documentation :

Notes

Windows Internet Explorer 8. In Windows Vista, pass CLSID_InternetExplorerMedium (defined in exdisp.idl) to CoCreateInstance to create an instance of Internet Explorer that runs at the integrity level . 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 a “medium level of integrity”, whatever that means? I didn’t think so.

+1
source

Source: https://habr.com/ru/post/1206857/


All Articles