欢迎访问 生活随笔!

生活随笔

当前位置: 首页 >

excel自动生成目录

发布时间:2025/6/15 40 豆豆
生活随笔 收集整理的这篇文章主要介绍了 excel自动生成目录 小编觉得挺不错的,现在分享给大家,帮大家做个参考.

2019独角兽企业重金招聘Python工程师标准>>>

用office excel打开excel文件
Alt+F11->插入->模块->把下面的代码拷贝到模块->F5         添加页签后重复此操作,目录自动生成

Sub mulu()On Error GoTo TuichuDim i As IntegerDim ShtCount As IntegerDim SelectionCell As RangeShtCount = Worksheets.CountIf ShtCount = 0 Or ShtCount = 1 Then Exit SubApplication.ScreenUpdating = FalseFor i = 1 To ShtCountIf Sheets(i).Name = "目录" ThenSheets("目录").Move Before:=Sheets(1)End IfNext iIf Sheets(1).Name <> "目录" ThenShtCount = ShtCount + 1Sheets(1).SelectSheets.AddSheets(1).Name = "目录"End IfSheets("目录").SelectColumns("B:B").Delete Shift:=xlToLeftApplication.StatusBar = "正在生成目录请等待!"For i = 2 To ShtCountActiveSheet.Hyperlinks.Add Anchor:=Worksheets("目录").Cells(i, 2), Address:="", SubAddress:="'" & Sheets(i).Name & "'!R1C1", TextToDisplay:=Sheets(i).NameNextSheets("目录").SelectColumns("B:B").AutoFitCells(1, 2) = "目录"Set SelectionCell = Worksheets("目录").Range("B1")With SelectionCell.HorizontalAlignment = xlDistributed.VerticalAlignment = xlCenter.AddIndent = True.Font.Bold = True.Interior.ColorIndex = 34End WithApplication.StatusBar = FalseApplication.ScreenUpdating = True Tuichu: End Sub

 


 

 

转载于:https://my.oschina.net/u/2540218/blog/551499

总结

以上是生活随笔为你收集整理的excel自动生成目录的全部内容,希望文章能够帮你解决所遇到的问题。

如果觉得生活随笔网站内容还不错,欢迎将生活随笔推荐给好友。