如何在Excel中使用chrome打开基于select的超链接

我知道你可以做

Sub Chrome() Dim chromePath As String chromePath = """C:\Program Files (x86)\Google\Chrome\Application\chrome.exe""" Shell (chromePath & " -url https://www.google.com") Shell (chromePath & " -url path") Shell (chromePath & " -url path") Shell (chromePath & " -url path") Shell (chromePath & " -url path") End Sub 

但是,如果我事先不知道超链接或URL,我不能真的把它们在代码中扭曲,我确实有超链接的单元格,我试图完成,以便能够selectX数量的单元格并打开Chrome中不同标签的超链接。

我尝试了一些愚蠢的行为

 Sub Open_HyperLinks() Dim chromePath As String chromePath = """C:\Program Files (x86)\Google\Chrome\Application\chrome.exe""" Dim hl As Hyperlink On Error Resume Next For Each hl In Selection.Hyperlinks Shell (chromePath & " -url hl") Next hl End Sub 

当然这不起作用…

您应该使用 链接集合中每个超链接.Address属性。

 Sub Open_HyperLinks() Dim chromePath As String, hl As Hyperlink chromePath = Environ("PROGRAMFILES(X86)") & "\Google\Chrome\Application\chrome.exe" 'On Error Resume Next For Each hl In Selection.Hyperlinks Shell chromePath & " -url " & hl.Address Next hl End Sub 

我从零开始解决了%PROGRAMFILES(X86)%环境variables,但硬编码的驱动器和path也应该正常工作。

Shell()方法将所有参数作为string传递给命令行。 确保“-url hl”中的hl对象不在引号内。 否则,Shell()传递“hl”作为超链接而不是“ https://www.google.com ”。

出于同样的原因,摆脱chromePath附近的额外引文。

尝试这个:

 Sub Open_HyperLinks() Dim chromePath As String chromePath = "C:\Program Files (x86)\Google\Chrome\Application\chrome.exe" Dim hl As Hyperlink On Error Resume Next For Each hl In Selection.Hyperlinks Shell (chromePath & " -url -newtab " & hl) Next hl End Sub 

注意:我没有testing过这些chrome可执行文件的标志。