gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-02 04:33:07 25 4
gpt4 key购买 nike

我在同一行收到两个不同的错误。有时是这个:

Automation error: object invoked has disconnected from its clients

有时:

the interface is unknown

重现错误的最少代码:

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 Controls

错误发生在 While ie.ReadyState <> 4第二次。我该如何解决这个问题?

最佳答案

这是 previously asked question 的重复项。该问题似乎是由 Internet Explorer 安全设置引起的 - 在安全区域之间切换时,当前的 IE 实例将被终止并创建一个新实例,因此您对旧进程的引用不再有效。

一些建议的解决方案是:

  1. 更改 IE 安全设​​置。取消选中“Internet 选项”的“安全”选项卡上的“启用保护模式”。
  2. 直接导航到 IP 地址而不是 URL。这是为我解决的问题。例如,ie.navigate "64.233.177.106"(Google 的 IP 地址)
  3. 设置 ie = New InternetExplorerMedium 而不是 New InternetExplorer。或者在你的情况下,反之亦然。

关于vba - 获取 InternetExplorer 对象的 ReadyState 时出现自动化错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26925206/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com