建立Excel目录及链接的VBA代码。
For i = 1 To Worksheets.Count
If Worksheets(i).Name = "目录" Then
Exit For
End If
Next
If i > Worksheets.Count Then
Sheets.Add
ActiveSheet.Name = "目录"
End If
Sheets("目录").Move before:=Sheets(1)
Sheets("目录").Select
Range("B:C").Clear
Range("B:B").NumberFormatLocal = "@"
Worksheets(1).Cells(1, 2).Value = "编号"
Worksheets(1).Cells(1, 3).Value = "目录"
For i = 2 To Worksheets.Count
Worksheets(1).Cells(i, 2).Value = i - 1
With Worksheets(1)
.Cells(i, 3).Value = Worksheets(i).Name
.Hyperlinks.Add Anchor:=Cells(i, 3), Address:="", SubAddress:= _
"'" & Worksheets(i).Name & "'!A1"
End With
Next