【问题标题】:VBA Internet explorer Automation errorVBA Internet Explorer 自动化错误
【发布时间】:2018-12-18 04:10:48
【问题描述】:

我试图建立一个公共测试环境,看看是否有人可以帮助我解决我今天早上问的另一个问题,我收到了这个错误,我在原始代码中没有遇到这个错误,并且在浏览了我无法修复:自动化错误 - 调用的对象已与其客户端断开连接

这里是完整的代码:

Sub GetBranches()
    Dim objIE As InternetExplorer
    Set objIE = New InternetExplorerMedium ' create new browser

    objIE.Visible = True

    objIE.navigate "https://casadasereia.net/vbatests/viewtree241653.html"

    ' wait for browser
    Do While objIE.Busy = True Or objIE.readyState <> 4
        DoEvents
    Loop
End Sub

有人知道如何解决这个问题吗?

【问题讨论】:

  • 试试这个 --> 将 Dim objIE As InternetExplorer Set objIE = New InternetExplorerMedium 更改为 Dim objIE as Object set objIE = CreateObject("InternetExplorer.Application")
  • 对!这行得通。我仍然需要了解创建对象的一种方法与另一种方法之间的原因和区别。但现在我很满足。请创建一个答案,我会接受它。
  • 感谢@Rawrplus。那篇文章中的 MS 支持网站的链接很棒:support.microsoft.com/en-us/help/245115/…

标签: excel vba internet-explorer automation


【解决方案1】:

使用后期绑定来避免对库的额外引用,这将解决版本控制问题(如果有的话)。

Sub GetBranches()
    Dim objIE as Object 
    Set objIE = CreateObject("InternetExplorer.Application")

    objIE.Visible = True

    objIE.navigate "https://casadasereia.net/vbatests/viewtree241653.html"

    ' wait for browser
    Do While objIE.Busy = True Or objIE.readyState <> 4
        DoEvents
    Loop
End Sub

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2020-07-11
    • 2016-11-05
    • 2017-06-25
    • 1970-01-01
    • 2021-07-15
    • 2016-09-24
    • 1970-01-01
    • 2015-04-27
    相关资源
    最近更新 更多