目录
How to Create a Dynamic Table of Contents in Excel
首页 系统教程 Windows系列 如何在Excel中创建动态目录

如何在Excel中创建动态目录

Mar 24, 2025 am 08:01 AM

A table of contents is a total game-changer when working with large files – it keeps everything organized and easy to navigate. Unfortunately, unlike Word, Microsoft Excel doesn’t have a simple “Table of Contents” button that adds this handy feature and updates it automatically. No, you’ll have to roll up your sleeves and create a dynamic table of contents yourself. This table will automatically update and contain clickable links, allowing you to add and remove sheets – as well as jump between them – with ease. This guide has all the info you need to create a dynamic table of contents in Excel.

How to Create a Dynamic Table of Contents in Excel

Technically, there are three ways to create a dynamic table of contents (TOC) in Excel. However, only one of them guarantees a fully automated TOC, and that’s Visual Basic for Applications or VBA for short – Microsoft’s native programming language. The other two – traditional formulas and Power Query – will give you a semi-dynamic table of contents in Excel – one that either doesn’t include clickable links or doesn’t update automatically. Since we’re after a fully dynamic Excel table of contents, we’ll use VBA.

If you aren’t particularly VBA-savvy; don’t worry – you just need to follow a few steps. But first – let’s create our table of contents.

Step 1: Click on the “Insert Worksheet” button next to your sheets at the bottom.

如何在Excel中创建动态目录

Step 2: Name the sheet “Table of Contents.”

如何在Excel中创建动态目录

Step 3: Drag the sheet to the first position for better navigation.

如何在Excel中创建动态目录

Step 4: Enter the names of your sheets in Column A of the “Table of Contents” sheet.

如何在Excel中创建动态目录

And voilà – you’ve got your table of contents. You can play with the aesthetics of this TOC later – now, we need to make it dynamic. To do so, we’ll need the help of the VBA Editor – a built-in Excel tool that lets you write and run custom codes.

Step 1: Press “Alt + F11” to open the VBA Editor.

如何在Excel中创建动态目录

Step 2: Go to the “Insert” tab at the top.

如何在Excel中创建动态目录

Step 3: Select “Module” from the dropdown menu.

如何在Excel中创建动态目录

Step 4: Copy and paste the following VBA code:

Sub CreateTOC()

    Dim ws As Worksheet

    Dim toc As Worksheet

    Dim i As Integer

    ‘ Check if TOC sheet already exists, delete if it does

    On Error Resume Next

    Set toc = ThisWorkbook.Sheets(“Table of Contents”)

    On Error GoTo 0

    If Not toc Is Nothing Then Application.DisplayAlerts = False: toc.Delete: Application.DisplayAlerts = True

    ‘ Create new TOC sheet

    Set toc = ThisWorkbook.Sheets.Add(Before:=ThisWorkbook.Sheets(1))

    toc.Name = “Table of Contents”

    ‘ Set up TOC header

    toc.Cells(1, 1).Value = “Table of Contents”

    toc.Cells(1, 1).Font.Bold = True

    toc.Cells(1, 1).Font.Size = 14

    ‘ Loop through all sheets and add hyperlinks

    i = 2

    For Each ws In ThisWorkbook.Sheets

        If ws.Name <> “Table of Contents” Then

            toc.Hyperlinks.Add Anchor:=toc.Cells(i, 1), _

                Address:=””, _

                SubAddress:=”‘” & ws.Name & “‘!A1”, _

                TextToDisplay:=ws.Name

            i = i + 1

        End If

    Next ws

    ‘ Adjust column width

    toc.Columns(“A”).AutoFit

 End Sub

如何在Excel中创建动态目录

Step 5: Hit “F5” to run the code.

Step 6: Exit the VBA Editor.

You’ll notice your Excel table of contents is now clickable.

如何在Excel中创建动态目录

To automatically update your table of contents after changes, you just need to repeat Steps 1 to 6. This will add any new sheets to the list or remove the ones you deleted.

如何在Excel中创建动态目录

以上是如何在Excel中创建动态目录的详细内容。更多信息请关注PHP中文网其他相关文章!

本站声明
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn

热门文章

仓库:如何复兴队友
3 周前 By 尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island冒险:如何获得巨型种子
3 周前 By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O.能量晶体解释及其做什么(黄色晶体)
1 周前 By 尊渡假赌尊渡假赌尊渡假赌

热门文章

仓库:如何复兴队友
3 周前 By 尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island冒险:如何获得巨型种子
3 周前 By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O.能量晶体解释及其做什么(黄色晶体)
1 周前 By 尊渡假赌尊渡假赌尊渡假赌

热门文章标签

记事本++7.3.1

记事本++7.3.1

好用且免费的代码编辑器

SublimeText3汉化版

SublimeText3汉化版

中文版,非常好用

禅工作室 13.0.1

禅工作室 13.0.1

功能强大的PHP集成开发环境

Dreamweaver CS6

Dreamweaver CS6

视觉化网页开发工具

SublimeText3 Mac版

SublimeText3 Mac版

神级代码编辑软件(SublimeText3)

框架桌面可能是我见过的最酷的小型PC 框架桌面可能是我见过的最酷的小型PC Mar 01, 2025 am 03:04 AM

框架桌面可能是我见过的最酷的小型PC

Powertoys是家庭伴侣应用程序的终极工作 Powertoys是家庭伴侣应用程序的终极工作 Mar 03, 2025 am 10:07 AM

Powertoys是家庭伴侣应用程序的终极工作

如何找到Windows 10的产品密钥 如何找到Windows 10的产品密钥 Mar 04, 2025 am 01:46 AM

如何找到Windows 10的产品密钥

如何在不支持的PC上安装Windows 11 23H2 如何在不支持的PC上安装Windows 11 23H2 Mar 03, 2025 pm 12:55 PM

如何在不支持的PC上安装Windows 11 23H2

如何更改PowerShell窗口的字体和布局 如何更改PowerShell窗口的字体和布局 Mar 03, 2025 pm 01:03 PM

如何更改PowerShell窗口的字体和布局

前3个Windows 11的游戏功能,使Windows 10超过Windows 10 前3个Windows 11的游戏功能,使Windows 10超过Windows 10 Mar 16, 2025 am 12:17 AM

前3个Windows 11的游戏功能,使Windows 10超过Windows 10

华硕Zenbook S 14(2024)评论:优质超便利的迭代精致 华硕Zenbook S 14(2024)评论:优质超便利的迭代精致 Mar 01, 2025 am 06:01 AM

华硕Zenbook S 14(2024)评论:优质超便利的迭代精致

2025年最好的人体工程学键盘 2025年最好的人体工程学键盘 Mar 03, 2025 am 10:02 AM

2025年最好的人体工程学键盘

See all articles