This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sub CreateTableOfContents() | |
'Step 1: Declare Variables | |
Dim i As Long | |
'Step 2: Delete Previous TOC worksheet if Exists | |
On Error Resume Next | |
With Application | |
.DisplayAlerts = False | |
.ScreenUpdating = False | |
End With | |
Sheets("TOC").Delete | |
On Error GoTo 0 | |
'Step 3: Add a new TOC worksheet as the first worksheet | |
ThisWorkbook.Sheets.Add Before:=ThisWorkbook.Worksheets(1) | |
ActiveSheet.Name = "TOC" | |
'Step 4: Start the i Counter | |
For i = 1 To Sheets.Count | |
'Step 5: Add Hyperlink | |
ActiveSheet.Hyperlinks.Add _ | |
Anchor:=ActiveSheet.Cells(i, 1), _ | |
Address:="", _ | |
SubAddress:="'" & Sheets(i).Name & "'!A1", _ | |
TextToDisplay:=Sheets(i).Name | |
'Step 6: Loop back | |
Next i | |
With Application | |
.DisplayAlerts = True | |
.ScreenUpdating = True | |
End With | |
End Sub |
No comments:
Post a Comment