【问题标题】:Using Chrome browser instead of InternetExplorer.Application使用 Chrome 浏览器而不是 InternetExplorer.Application
【发布时间】:2015-05-03 20:12:53
【问题描述】:

我知道如何使用 Excel VBA 和 IE,但我想知道是否可以使用 Google Chrome,因为我发现它比 IE 更快。

这就是我的具体意思:

Set IE = CreateObject("InternetExplorer.Application")

我可以用启动 Chrome 而不是 IE 的东西来代替它吗?

【问题讨论】:

  • 是的,只要它安装在您的计算机上,您就可以使用命令行在 Chrome 中启动该 URL。您将无法使用它来解析 .Document,就像 InternetExplorer.Application 对象一样。
  • 它已安装在我的计算机上,但我需要使用它来解析 .Document 那么,没有解决方法可以实现吗?
  • 如果您想要比 ie 对象更快的东西,请开始查看 XMLHTTP 库。

标签: vba google-chrome internet-explorer excel


【解决方案1】:

Google Chrome 不像 Internet Explorer 那样提供 Visual Basic 界面,因此您无法访问它的任何属性(例如 Document)。您只需传递给可执行文件即可在特定地址启动 chrome。

例如:

Dim path As String = Environment.GetFolderPath(Environment.SpecialFolder.ProgramFiles)
Dim executable As String = Path.Combine(path, "Google\\Chrome\\Application\\chrome.exe")

Process.Start(executable, "http://google.com")

【讨论】:

  • 该问题要求一个可以通过 API 远程控制的浏览器对象,而不是如何启动 Chrome.exe。
【解决方案2】:

有一个名为 Selenium 的优秀资源库,其中包含 VBA Wrappers。有一个非常基础的教程 here,但如果你真的想完成任何事情,最好的起点是示例电子表格 hosted here

【讨论】:

    【解决方案3】:
    Sub test544()
      Dim chromePath As String
      chromePath = """C:\Program Files\Google\Chrome\Application\chrome.exe"""
      Shell (chromePath & " -url http:google.ca")
    End Sub
    

    【讨论】:

    • 虽然这段代码 sn-p 可以解决问题,including an explanation 确实有助于提高您的帖子质量。请记住,您是在为将来的读者回答问题,而这些人可能不知道您提出代码建议的原因。
    • 该问题要求一个可以通过 API 远程控制的浏览器对象,而不是如何启动 Chrome.exe。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-03-14
    • 2022-06-29
    • 2012-04-16
    • 2019-12-24
    相关资源
    最近更新 更多