Hyperlink to Worksheet in actual Workbook

borlee picture borlee · Jan 27, 2011 · Viewed 22.4k times · Source

How can i add a Hyperlink to a specific cell and address it to a Worksheet in the Excel file?

This is what I already got:

Cells(zeile, 1).Select
Worksheets(1).Hyperlinks.Add Anchor:=Selection, Address:=Workbooks(1).Worksheets(fortnr), SubAddress:=Cells(1, 1).Address

Thanks.

Answer

Dick Kusleika picture Dick Kusleika · Jan 27, 2011
ActiveSheet.Hyperlinks.Add ActiveCell, "", Sheets(fortnr).Name & "!A1"

The Address should be blank and the SubAddress should be in the form Sheet1!A1. This puts a link in the activecell assuming you have a variable named fortnr that contains a valid sheet name in the same workbook.

If you want to point to a cell in a different workbook, then everything is the same except the Address needs to be that file.

ActiveSheet.Hyperlinks.Add ActiveCell, Workbooks(1).FullName, Sheets(fortnr).Name & "!A1"

Assuming Workbooks(1) is a different file and has been previously saved and has a sheet with the right name, etc, etc.