如何使用chrome打开excel中的超链接

时间:2016-06-22 14:07:03

标签: excel vba hyperlink

我有一个代码可以从chrome中的excel表打开超链接。它工作得很好,但我注意到一个奇怪的行为,它打开超链接不是从上下顺序但使用一些标准,我不明白它不是随机的,因为测试时我注意到它总是打开相同顺序的链接即

超链接1 超链接2 超链接3 超链接4 超链接5

它会一直打开

超链接2超链接1超链接3超链接4超链接5

每当我运行代码时,它按顺序打开它我需要它以从上到下的顺序打开超链接。这是代码

Sub Open_HyperLinks()
    Dim chromePath As String, hl As Hyperlink

    chromePath = Environ("PROGRAMFILES(X86)") & "\Google\Chrome\Application\chrome.exe"
 If Selection.Count > 1 Then
    Selection.SpecialCells(xlCellTypeVisible).Select
 End If
    'On Error Resume Next
    For Each hl In Selection.Hyperlinks
        Shell chromePath & " -url " & hl.Address
      Next hl
End Sub

1 个答案:

答案 0 :(得分:0)

Don't use .Select,因为它可能会导致问题。

这对你有用吗?

Sub Open_HyperLinks()
Dim chromePath As String, hl As Hyperlink
Dim rng As Range, visRng As Range

chromePath = Environ("PROGRAMFILES(X86)") & "\Google\Chrome\Application\chrome.exe"

Set rng = Selection

If rng.Count > 1 Then
    Set visRng = rng.SpecialCells(xlCellTypeVisible)
End If
'On Error Resume Next
For Each hl In visRng.Hyperlinks

    Shell chromePath & " -url " & hl.Address
Next hl
End Sub