从 VBA/Excel 打开谷歌浏览器
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/5915325/
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
Open Google Chrome from VBA/Excel
提问by Sam
I'm trying to open a Chrome browser from VBA. I understand Chrome does not support ActiveX settings so I'm curious if theres any work-arounds?
我正在尝试从 VBA 打开 Chrome 浏览器。我知道 Chrome 不支持 ActiveX 设置,所以我很好奇是否有任何解决方法?
Dim ie As Object
Set ie = CreateObject("ChromeTab.ChromeFrame")
ie.Navigate "google.ca"
ie.Visible = True
回答by ray
shell("C:\Users\USERNAME\AppData\Local\Google\Chrome\Application\Chrome.exe -url http:google.ca")
回答by ahmad
Worked here too:
也在这里工作过:
Sub test544()
Dim chromePath As String
chromePath = """C:\Program Files\Google\Chrome\Application\chrome.exe"""
Shell (chromePath & " -url http:google.ca")
End Sub
回答by Diego Martinez
I found an easier way to do it and it works perfectly even if you don't know the path where the chrome is located.
我找到了一种更简单的方法,即使您不知道 chrome 所在的路径,它也能完美运行。
First of all, you have to paste this code in the top of the module.
首先,您必须将此代码粘贴到模块的顶部。
Option Explicit
Private pWebAddress As String
Public Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" _
(ByVal hwnd As Long, ByVal lpOperation As String, ByVal lpFile As String, _
ByVal lpParameters As String, ByVal lpDirectory As String, ByVal nShowCmd As Long) As Long
After that you have to create this two modules:
之后,您必须创建这两个模块:
Sub LoadExplorer()
LoadFile "Chrome.exe" ' Here you are executing the chrome. exe
End Sub
Sub LoadFile(FileName As String)
ShellExecute 0, "Open", FileName, "http://test.123", "", 1 ' You can change the URL.
End Sub
With this you will be able (if you want) to set a variable for the url or just leave it like hardcode.
有了这个,您将能够(如果您愿意)为 url 设置一个变量,或者像硬编码一样保留它。
Ps: It works perfectly for others browsers just changing "Chrome.exe" to opera, bing, etc.
Ps:它适用于其他浏览器,只需将“Chrome.exe”更改为opera、bing等即可。
回答by Stephen
You can use the following vba code and input them into standard module in excel. A list of websites can be entered and should be entered like this on cell A1 in Excel - www.stackoverflow.com
您可以使用以下vba代码并将它们输入到excel的标准模块中。可以输入网站列表,并且应该像这样在 Excel 的单元格 A1 上输入 - www.stackoverflow.com
ActiveSheet.Cells(1,2).Value merely takes the number of website links that you have on cell B1 in Excel and will loop the code again and again based on number of website links you have placed on the sheet. Therefore Chrome will open up a new tab for each website link.
ActiveSheet.Cells(1,2).Value 仅获取您在 Excel 中单元格 B1 上拥有的网站链接数,并将根据您放置在工作表上的网站链接数一次又一次地循环代码。因此,Chrome 将为每个网站链接打开一个新标签。
I hope this helps with the dynamic website you have got.
我希望这对您拥有的动态网站有所帮助。
Sub multiplechrome()
Dim WebUrl As String
Dim i As Integer
For i = 1 To ActiveSheet.Cells(1, 2).Value
WebUrl = "http://" & Cells(i, 1).Value & """"
Shell ("C:\Program Files (x86)\Google\Chrome\Application\chrome.exe -url " & WebUrl)
Next
End Sub
回答by getinmazone
The answer given by @ray above works perfectly, but make sure you are using the right path to open up the file. If you right click on your icon and click properties, you should see where the actual path is, just copy past that and it should work.
上面@ray 给出的答案非常有效,但请确保您使用正确的路径打开文件。如果您右键单击您的图标并单击属性,您应该会看到实际路径的位置,只需复制过去即可。