0
votes

My Excel-Worksheet contains some cells with hyperlinks to other sheets in the same document.

How can I go to this new sheet or save it in a variable using VBA ?

Hyperlinks(1).Follow did not work.

Thank you in advance

1
Are you fully qualyfing the Hyperlinks collection (i.e. Sheets("yourSheet").Range("yourRange").Hyperlinks(1).Follow? Are you sure the hyperlink you want to follow is the first one? What does did not work mean? It doesn't go to the page, it gives you an error, it does nothing?Matteo NNZ
P.s. if you need to execute the action of changing sheet, I would rather suggest yourSheet.Activate or yourSheet.Select, much easier and not relying on hyperlinks that the user might decide to delete.Matteo NNZ
I need to parse elements in the other Sheet. .Follow gives an error with internal hyperlink (what I need)Leon

1 Answers

0
votes

Below code give you addresses as message boxes, you can write whatever you want within there.

You need to be careful about if the link is within the same workbook it is recorded as SubAddress, if it is an external link it is recorded as Address

Sub LinkFind()
    For Each lnk In ActiveSheet.Cells.Hyperlinks
        MsgBox lnk.SubAddress
    Next
End Sub

Following code does not make any sense but just to show you visiting procedure:

Sub LinkVisit()
Dim ws As Worksheet
Set ws = ActiveSheet '<- or Sheets("Sheetname")
    For Each lnk In ws.Cells.Hyperlinks
        lnk.Follow
    Next
End Sub