0

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
Tom Ruiz
  • 307
  • 1
  • 6
  • 20
  • Where/how are the URLs stored? In a single cell? I one row or one column? Is Chrome closed when you run your code? – Tom K. Jun 22 '16 at 14:10
  • Each hyperlink is stored in a single cell, for example hyperlink 1 is in cell A1 hyperlink 2 cell A2 and so on... chrome is open – Tom Ruiz Jun 22 '16 at 15:17

1 Answers1

0

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
Community
  • 1
  • 1
BruceWayne
  • 22,923
  • 15
  • 65
  • 110
  • Nope still not opening them in order I wonder if what I'm trying to do is possible I tried `Application.Wait Now() + TimeValue("00:00:01")` but still same behaviour – Tom Ruiz Jun 23 '16 at 21:25