生活随笔
收集整理的這篇文章主要介紹了
excel自动生成目录
小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
2019獨角獸企業(yè)重金招聘Python工程師標準>>>
用office excel打開excel文件
Alt+F11->插入->模塊->把下面的代碼拷貝到模塊->F5???????? 添加頁簽后重復(fù)此操作,目錄自動生成
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
?
?
?
轉(zhuǎn)載于:https://my.oschina.net/u/2540218/blog/551499
總結(jié)
以上是生活随笔為你收集整理的excel自动生成目录的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。