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
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
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 NNZyourSheet.Activate
oryourSheet.Select
, much easier and not relying on hyperlinks that the user might decide to delete. – Matteo NNZ