My workbook contains at least 30 sheets. I will like the code to automatically
create the table of content for me. I do have a code which does just that but
the problem with this code is that if one of my sheets name has a space or dash,
the hyperlink for that sheet won't work. I am fine when I have a new workbook I
can Name he sheet with one word or an underscore, but I inherited some old files
which the names have no consistency. I pasted the code below.
Thank you for your help again
Sub CreateTable()
Dim ws As Worksheet, wsTOC As Worksheet
Dim r As Long
Application.ScreenUpdating = False
Set wsTOC = ActiveWorkbook.Worksheets.Add _
(Before:=ActiveWorkbook.Sheets(1))
wsTOC.Name = "Table of Contents"
wsTOC.Range("A1") = "Table of Contents"
wsTOC.Range("A1").Font.Size = 16
r = 3
For Each ws In ActiveWorkbook.Worksheets
If ws.Name <> wsTOC.Name Then
wsTOC.Hyperlinks.Add _
Anchor:=wsTOC.Cells(r, 1), _
Address:="", _
SubAddress:=ws.Name & "!a1", _
TextToDisplay:=ws.Name
r = r + 1
End If
Next
Application.ScreenUpdating = True
End Sub