我有一段代码,可以在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发布于 2016-06-24 02:11:41
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 Subhttps://stackoverflow.com/questions/37970491
复制相似问题