Hi everyone,
I am quite new to using VBA and I am having issues using hyperlinks. Essentially I am trying to create a table of contents where if I select the hyperlink (In the same document) on the table of contents sheet it will simply direct me to the following sheet i.e. selecting page 1 will direct me to page 1. However, it is showing that the reference is not valid.
If you could help it would be much appreciated.
Thanks,
Tmatti92
I am quite new to using VBA and I am having issues using hyperlinks. Essentially I am trying to create a table of contents where if I select the hyperlink (In the same document) on the table of contents sheet it will simply direct me to the following sheet i.e. selecting page 1 will direct me to page 1. However, it is showing that the reference is not valid.
VBA Code:
Sub auto_TOC()
Dim sh As Worksheet
Dim startcell As Range
Dim shname As String
Set startcell = Excel.Application.InputBox("Select where you want to insert" _
& "table of contents", "Table Of Contents", , , , , , 8)
Set startcell = startcell.Cells(1, 1)
For Each sh In Worksheets
shname = sh.Name
If ActiveSheet.Name <> sh.Name Then
ActiveSheet.Hyperlinks.Add Anchor:=startcell, Address:="", SubAddress:= _
shname & "!A1", TextToDisplay:=shname
startcell.Offset(0, 1).Value = sh.Range("A1").Value
Set startcell = startcell.Offset(1, 0)
End If
Next sh
End Sub
If you could help it would be much appreciated.
Thanks,
Tmatti92