获取InternetExplorer对象的ReadyState时出现自动化错误 [英] 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
有时:
界面未知
重现错误的最小代码:
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
这需要参考:工具">参考...">"Microsoft Internet控件"
This requires a reference: Tools > References... > Microsoft Internet Controls
该错误第二次出现在While ie.ReadyState <> 4
上.我该如何解决?
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:
- 更改IE安全设置.取消选中"Internet选项"的安全"选项卡上的启用保护模式".
- 直接导航到IP地址而不是URL.这是为我修复的.例如,
ie.navigate "64.233.177.106"
(Google的IP地址) -
Set ie = New InternetExplorerMedium
而不是New InternetExplorer
.反之亦然.
- 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 ofNew InternetExplorer
. Or in your case, vice versa.
这篇关于获取InternetExplorer对象的ReadyState时出现自动化错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!