一个工作簿里面有很多的表格,我想添加一个目录表格,便于快速切换到我想要的某个表格中,百度了解到可以通过代码解决,步骤是在ThisWorkbook中输入以下代码,可是我在WPS中找不到ThisWorkbook,又听闻说是EXCEL2003版本就支持,而之后的版本和WPS是不支持,请教各位大佬有办法解决的吗?我试过用WPS中的智能工具箱来添加目录,可是当我删除某个表格或者修改表格名称时,修改名称表格的超链接就不支持了。
代码如下:
Private Sub Workbook_SheetActivate(ByVal Sh As Object)
Dim r%, ml As Worksheet
Set ml = Sheets("目录")
ml.Range("a:a").ClearContents
ml.Range("a1") = "工作表目录"
r = 1
For Each Sh In ThisWorkbook.Sheets
If Sh.Name <> "目录" Then
r = r + 1
ml.Hyperlinks.Add anchor:=ml.Cells(r, 1), Address:="", _ SubAddress:="'" & Sh.Name & "'!a1", TextToDisplay:=Sh.Name
Sh.Hyperlinks.Add anchor:=Sh.Cells(1, 13), Address:="", _ SubAddress:="'目录'!a1", TextToDisplay:="返回目录"
With Sh.Cells(1, 15).Font
.Name = "微软雅黑"
.Size = 11
.Underline = xlUnderlineStyleNone
End With
End If
Next Sh
With ml.Range("a1").CurrentRegion
With .Font
.Name = "微软雅黑"
.Size = 11
.Underline = xlUnderlineStyleNone
End With
.HorizontalAlignment = xlLeft
End With
ml.Columns.AutoFit
End Sub
|