【问题标题】:IE.LocationURL returns error when URL not resolvedIE.LocationURL 在 URL 未解析时返回错误
【发布时间】:2020-01-09 02:14:09
【问题描述】:

我有一个基本的 VBA 脚本,它可以打开 InternetExplorer 窗口,以便用户可以授权 OAuth2.0 连接。作为此过程的一部分,他们的浏览器被重定向到包含访问令牌的回调地址。目前,我将重定向 URL 设置为http://localhost。

脚本在带有 MS Access 2010 和 Internet Explorer 11 的 Windows 10 上正常运行。但是,在另一台 Win 10 PC 上的 MS Access 2016 中,我收到错误 -2147023179 Automation error The interface is unknown.。我已经确认重定向 URL 是正确的,并且我还硬编码了一个可解析的重定向 URL,它也可以工作。

似乎当 InternetExplorer 遇到无法解析的 URL 时,它会中断与 IE 实例的 VBA 连接。我正在寻找可以帮助我规避此问题的信息。

下面的代码是我正在使用的:

Dim IE as InternetExplorer

' create IE instance
Set IE = CreateObject("InternetExplorer.Application")

Dim url as String: url = "www.some-website.com"

' show IE
IE.Visible = True

' navigate to OAuth authorize URl
IE.Navigate url

' wait for page to load
Do While IE.ReadyState = 4: DoEvents: Loop

' loop until callback url in address bar
' ERROR HAPPENS HERE
While InStr(1, IE.LocationURL, "http://localhost") <= 0
    DoEvents
Wend

【问题讨论】:

    标签: vba internet-explorer


    【解决方案1】:

    请尝试使用 InternetExplorerMedium 对象而不是 InternetExplorer 对象。更多详细信息,您可以查看以下链接:

    Excel VBA Controlling IE local intranet

    使用 InternetExplorerMedium 对象时,您可能需要添加对 Microsoft Internet 控件的引用,您可以查看此链接:

    How to add VBA References – Internet Controls, HTML Object Library

    【讨论】:

    • 感谢您的回答。在我的情况下,我必须使用 InternetExplorerMedium 并使用第一个链接中的 shell 技巧循环打开窗口。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2015-09-28
    • 1970-01-01
    • 2013-04-13
    • 2012-04-12
    • 1970-01-01
    • 2021-10-19
    • 1970-01-01
    相关资源
    最近更新 更多