|
[广告] VBA代码宝 - VBA编程加强工具 · VBA代码随查随用 · 内置多项VBA编程加强工具 ★ 免费下载 ★ ★ 使用手册★
我现在知道我的工作簿名称是复制修改的,超链接做完后,要每一个再点编辑一次才能变正常
Sub Create_Index()
Dim Sht As Worksheet, Ar, K%
ReDim Ar(1 To Sheets.Count + 1, 1 To 2) '定义Ar空间结构
Ar(1, 1) = "序号": Ar(1, 2) = "目录" '字段命名
K = 1
For Each Sht In Worksheets
K = K + 1
Ar(K, 1) = K - 1: Ar(K, 2) = Sht.Name
If Ar(K, 2) = "目录" Then
MsgBox "已存名字为'Sheets_Index'的工作表,请改名或者删除"
Exit Sub
End If
Next '工作表名字装入Ar
Sheets.Add before:=Sheets(1) '创建序列1的Sheet
With Sheets(1)
.Name = "目录"
.[a1].Resize(K, 2) = Ar
.UsedRange.Borders.LineStyle = 1
.UsedRange.Columns.AutoFit
For K = 2 To UBound(Ar)
.Hyperlinks.Add anchor:=Cells(K, 2), Address:="", SubAddress:=Ar(K, 2) & "!A1", TextToDisplay:=Ar(K, 2)
Next K
End With
End Sub
|
|