自动创建Excel sheet页索引的办法

方法一:

1)先下载一个Excel文件:http://vdisk.weibo.com/s/lKO2s

2)把Catalog页移动到需要建立索引的Excel文件中

3)右键Create按钮 - Assign Macro... - 选择:Catalog.Create_DropDown_MainMenu

右键Clear按钮 - Assign Macro... - 选择:Catalog.DeleteSpecifyShapes

4)点击Create即可生成目录:

自动创建Excel sheet页索引的办法_第1张图片



方法二:

首先打开要创建目录的EXCEL文件 —— Alt+F11——插入——模块——把下面的代码拷贝到模块中:

然后Tools - Macro - Macros,选中刚刚创建的mulu,Run;就会生成一个新的目录sheet页。


BUT,测试后发现有些索引点击后报错:

自动创建Excel sheet页索引的办法_第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 = True
Tuichu:
End Sub

你可能感兴趣的:(自动创建Excel sheet页索引的办法)