Excel Macro code to Create a Table of Content

Share on facebook
Share on linkedin
Share on email
Share on whatsapp

How to Create a Table of Content in excel sheet through VBA Macro Code

For using this VBA macro code in excel to Create a Table of Content you will have copy below Macro code in Excel Visual Basic Editor
Sub TableofContent()
Dim i As Long
On Error Resume Next
Application.DisplayAlerts = False
Worksheets("Table of Content").Delete
Application.DisplayAlerts = True
On Error GoTo 0
ThisWorkbook.Sheets.Add Before:=ThisWorkbook.Worksheets(1)
ActiveSheet.Name = "Table of Content"
For i = 1 To Sheets.Count
With ActiveSheet
.Hyperlinks.Add _
Anchor:=ActiveSheet.Cells(i, 1), _
Address:="", _
SubAddress:="'" & Sheets(i).Name & "'!A1", _
ScreenTip:=Sheets(i).Name, _
End With
Next i
End Sub

How to Create a Table of Content in excel through VBA macro code?

Let’s say you have more than 100 worksheets in your workbook and it’s hard to navigate now. Don’t worry this macro code will rescue everything. When you run this code it will create a new worksheet and create a index of worksheets with a hyperlink to them.

What is a Macro Code?

In MS Excel, macro code is a programming code which is written in VBA (Visual Basic for Applications) language.

The idea is to use macro code for automating various activities which you perform manually in Excel, otherwise.

For example, you can use a code to print only a particular range of cells just with a single click instead of selecting the range -> File Tab -> Print -> Print Select -> OK Button.

How to use a Macro Code in Excel


  • On the left side in “Project Window”, right click on the name of your workbook and insert a new module.


  • Just paste your code into the module and close it.


  • Now, go to your developer tab and click on the macro button.


  • It will show you a window with a list of the macros you have in your file from where you can run a macro from that list.





Training Attendance Sheet

Whether you’re organizing any training program for an athletic event. A technology course, or a chess tournament, a good attendance …

Download Now

Weekly Attendance Sheet

Our “Weekly Attendance Sheet” is simple, compact, and useful an all-purpose attendance tracker. This attendance tracker includes one worksheet with …

Download Now

Student Attendance Sheet

These student attendance sheet records is create to help teachers keep track of attendance of their students. There are two …

Download Now

Shift Planner with Tracker

Shift Planner with Tracker for Excel is a powerful spreadsheet that help any Human Resources or operational managers creating their …

Download Now

Employee Attendance Tracker

The free employee attendance tracker template is one of my popular excel templates. I have create a more general employee …

Download Now

Islamic Calendar

The Islamic calendar (it is known also as Muslim calendar or Hijri calendar) is a lunar calendar based on 12 …

Download Now