Building a TOC

P

phil1ray

Over a year ago a member of this forum directed me to a web sight wit
the code for a macro to build a table of contents in a work book.
have since deleted the macro and now I need it again. Can anyone help.

Thank
 
J

JMB

I don't know the web site, but are you trying to generate a list (hyperlinks)
of the sheets in your workbook? You could do that with (or something like)
the following (which begins the list in the active cell - be sure not to
overwrite anything you need):

Sub TOC()
Dim i As Long
Dim Counter As Long
Counter = 0

For i = 1 To Sheets.Count
If Sheets(i).Name <> ActiveSheet.Name Then
ActiveSheet.Hyperlinks.Add Anchor:=ActiveCell.Offset(Counter, 0), _
Address:="", SubAddress:=Sheets(i).Name & "!A1", _
TextToDisplay:=Sheets(i).Name
Counter = Counter + 1
End If
Next i

End Sub
 
Top