vba 获取 InternetExplorer 对象的 ReadyState 时出现自动化错误

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/26925206/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-08 09:08:42  来源:igfitidea点击:

Automation error when getting ReadyState of InternetExplorer object

vbainternet-explorerexcel-vbaexcel

提问by Amar

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

这需要参考:工具 > 参考... > Microsoft Internet Controls

The error occurs on While ie.ReadyState <> 4the second time. How do I fix this?

While ie.ReadyState <> 4第二次出现错误。我该如何解决?

回答by Elizabeth Amato

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.

这是先前提出的问题的副本。该问题似乎是由 Internet Explorer 安全设置引起的 - 在安全区域之间切换时,IE 的当前实例被杀死并创建了一个新实例,因此您对旧进程的引用不再有效。

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 InternetExplorerMediuminstead of New InternetExplorer. Or in your case, vice versa.
  1. 更改 IE 安全设​​置。在 Internet 选项的安全选项卡上取消选中“启用保护模式”。
  2. 直接导航到 IP 地址而不是 URL。这是为我修复它的那个。例如,ie.navigate "64.233.177.106"(谷歌的 IP 地址)
  3. Set ie = New InternetExplorerMedium而不是New InternetExplorer. 或者在你的情况下,反之亦然。

回答by Jean-Fran?ois Corbett

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 InternetExplorerMediumin the first place. Quoting the small print in the documentation:

我不确定你为什么会InternetExplorerMedium首先使用。引用文档中的小字:

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 InternetExplorerMediumobject supports the same events, methods, and properties as the InternetExplorerobject.

评论

Windows Internet Explorer 8. 在 Windows Vista 上,要创建以中等完整性级别运行的 Internet Explorer 实例,CLSID_InternetExplorerMedium请将(在 exdisp.idl 中定义)传递给CoCreateInstance。结果InternetExplorerMedium对象支持与对象相同的事件、方法和属性InternetExplorer

Are you really using IE8 on Windows Vista, and do you really want "medium integrity level", whatever that means? I didn't think so.

您真的在 Windows Vista 上使用 IE8,并且您真的想要“中等完整性级别”,无论这意味着什么?我不这么认为。

回答by user12806112

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.

打开Internet Explorer,然后进入Internet设置,打开“站点”并清除需要服务器验证的网页。问题是服务器comprobation。