手抄报 安全手抄报 手抄报内容 手抄报图片 英语手抄报 清明节手抄报 节约用水手抄报

快速根据工作表名称生成一个sheet目录,只需3步

时间:2024-10-11 22:14:33

1、打开需要建立目录的excel表格文件,按快捷组合键ALT+F11,调出VBA开发平台,点击插入——模块,

快速根据工作表名称生成一个sheet目录,只需3步

2、复制代码Sub mulu() On Error GoTo Tuichu Dim i As Integer Dim ShtCount As Integer 肛舀辨乔Dim SelectionCell As Range ShtCount = Worksheets.Count If ShtCount = 0 Or ShtCount = 1 Then Exit Sub Application.ScreenUpdating = False For i = 1 To ShtCount If Sheets(i).Name = "目录" Then Sheets("目录").Move Before:=Sheets(1) End If Next i If Sheets(1).Name <> "目录" Then ShtCount = ShtCount + 1 Sheets(1).Select Sheets.Add Sheets(1).Name = "目录" End If Sheets("目录").Select Columns("B:B").Delete Shift:=xlToLeft Application.StatusBar = "正在生成目录…………请等待!" For i = 2 To ShtCount ActiveSheet.Hyperlinks.Add Anchor:=Worksheets("目录").Cells(i, 2), Address:="", SubAddress:= _ "'" & Sheets(i).Name & "'!R1C1", TextToDisplay:=Sheets(i).Name Next Sheets("目录").Select Columns("B:B").AutoFit Cells(1, 2) = "目录" Set SelectionCell = Worksheets("目录").Range("B1") With SelectionCell .HorizontalAlignment = xlDistributed .VerticalAlignment = xlCenter .AddIndent = True .Font.Bold = True .Interior.ColorIndex = 34 End With Application.StatusBar = False Application.ScreenUpdating = TrueTuichu:End Sub黏贴到模块里,保存

快速根据工作表名称生成一个sheet目录,只需3步

3、按F5或点击图标运行,即可生成这样一份工作表名称目录,点击相应的名称即可跳转到相应的工作表。

快速根据工作表名称生成一个sheet目录,只需3步
© 手抄报圈