Created
September 13, 2017 14:42
-
-
Save longtth/7670c5fe3721d9f4d3f45b949e811a85 to your computer and use it in GitHub Desktop.
Tạo sheet Mục lục trong excel với mỗi link là 1 sheet
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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment