简体   繁体   English

如何使用Chrome在Excel中按顺序打开超链接

[英]How to open hyperlinks in excel in order using chrome

I have a code to open hyperlinks from an excel sheet in chrome. 我有一个代码可以从chrome的excel表格中打开超链接。 it works just fine, however I have noticed a strange behavior, it opens the hyperlinks not in from up t down order but using some criteria I don't understand it's not randomly because when testing I noticed it always opened the links in tha same order ie 它工作正常,但是我注意到一个奇怪的行为,它不是按照从上到下的顺序打开超链接,而是使用一些标准,我不明白它不是随机的,因为在测试时我注意到它总是以相同的顺序打开链接即

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

It would always open 它会一直打开

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

Everytime I ran the code it open them in that order I need it to open the hyperlinks in a top to bottom order. 每次我运行代码时,它都以这种顺序打开它们,我需要它以从上到下的顺序打开超链接。 Here is the code 这是代码

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

Don't use .Select , as it can cause issues. 不要使用.Select ,因为它可能会引起问题。

Does this work for you? 这对您有用吗?

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM