vba 使用 Chrome 浏览器代替 InternetExplorer.Application

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/30018858/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-08 09:34:12  来源:igfitidea点击:

Using Chrome browser instead of InternetExplorer.Application

excelvbagoogle-chromeinternet-explorerexcel-vba

提问by GeneralS

I know how to work with Excel VBA and IE, but I would like to know if it's possible to work with Google Chrome, since I find it faster than IE.

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

Here's what I mean specifically:

这是我具体的意思:

Set IE = CreateObject("InternetExplorer.Application")

Can I substitute this with something that will launch Chrome instead of IE?

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

回答by Hyman Wilsdon

Google Chrome does not provide a Visual Basic interface like Internet Explorer does, so you cannot access any of it's properties (e.g. Document). You can launch chrome at a specific address just by passing to the executable.

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

For example:

例如:

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")

回答by Martin KS

There's an excellent resource library called Selenium that has VBA Wrappers. There's a very basic tutorial here, though if you really want to get anything done the best starting point is the example spreadsheet hosted here.

有一个名为 Selenium 的优秀资源库,其中包含 VBA 包装器。有一个非常基本的教程在这里,但如果你真的想要得到什么做的最好的出发点是例如电子表格此间举行

回答by Helpeachother

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