您的位置:首页 > 其它

Excel Skill---Generate Table of Contents based on Sheet Name (根据Sheet名称产生目录)

2015-03-16 16:59 465 查看
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 = "Inventory" Then
Sheets("Inventory").Move Before:=Sheets(1)
End If
Next i
If Sheets(1).Name <> "Inventory" Then
ShtCount = ShtCount + 1
Sheets(1).Select
Sheets.Add
Sheets(1).Name = "Inventory"
End If
Sheets("Inventory").Select
Columns("B:B").Delete Shift:=xlToLeft
Application.StatusBar = "Generating Inventory…………WAITING!"
For i = 2 To ShtCount
ActiveSheet.Hyperlinks.Add Anchor:=Worksheets("Inventory").Cells(i, 2), Address:="", SubAddress:= _
"'" & Sheets(i).Name & "'!R1C1", TextToDisplay:=Sheets(i).Name
Next
Sheets("Inventory").Select
Columns("B:B").AutoFit
Cells(1, 2) = "Inventory"
Set SelectionCell = Worksheets("Inventory").Range("B1")
With SelectionCell
.HorizontalAlignment = xlDistributed
.VerticalAlignment = xlCenter
.AddIndent = True
.Font.Bold = True
.Interior.ColorIndex = 34
End With
Application.StatusBar = False
Application.ScreenUpdating = True
Tuichu:
End Sub
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐