'How to open hyperlinks in excel in order using chrome
I have a code to open hyperlinks from an excel sheet in chrome. 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 i.e
Hyperlink 1 Hyperlink 2 Hyperlink 3 Hyperlink 4 Hyperlink 5
It would always open
Hyperlink 2 Hyperlink 1 Hyperlink 3 Hyperlink 4 Hyperlink 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
Solution 1:[1]
Don't use .Select, as it can cause issues.
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
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Community |
