首页 > 解决方案 > VBA Internet Explorer 自动化错误

问题描述

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

自动化错误 - 调用的对象已与其客户端断开连接

这是完整的代码:

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

任何人都知道如何解决这个问题?

标签: excelvbainternet-explorerautomation

解决方案


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

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

推荐阅读