excel利用VBA制作包含超链接的工作表目录
时间:2022-10-20 05:06:50
如果Excel工作簿中包含许多工作表,可以在一个工作表中列出所有工作表目录和相关说明,以方便在各工作表之间跳转。下面的VBA代码就可以实现这个功能,可以在某个工作表的第一列中产生其他工作表的目录列表及其超链接,单击工作表名称就可以跳转到相应的工作表中,并且可以在其他工作表的A1单元格中设置一个返回目录的超链接,单击可以返回到包含目录的工作表中。
按Alt+F11,打开VBA编辑器,在“工程”窗口中双击要设置目录列表的工作表名称,在右侧代码窗口中输入下面的代码后运行:
Sub CreateSheetsIndex()
Dim wSheet As Worksheet
Dim i As Long
i = 1
With Me
.Columns(i).ClearContents
.Cells(1, 1) = "工作表目录"
.Cells(1, 1).Name = "目录"
End With
For Each wSheet In Worksheets
If wSheet.Name <> Me.Name Then
i = i + 1
With wSheet
.Range("A1").Name = "工作表" & wSheet.Index
.Hyperlinks.Add Anchor:=.Range("A1"), Address:="", SubAddress:="目录", ScreenTip:= _
"跳转到“" & Me.Name & "”工作表", TextToDisplay:="返回目录"
End With
Me.Hyperlinks.Add Anchor:=Me.Cells(i, 1), Address:="", SubAddress:="工作表" & wSheet.Index, _
ScreenTip:="跳转到“" & wSheet.Name & "”工作表", TextToDisplay:=wSheet.Name
End If
Next wSheet
End Sub
说明:
1.由于上述代码会在所有工作表的A1单元格输入链接内容,所以运行代码前务必确保A1单元格为空。
2.如果工作表有密码保护,请先解除保护。
3.运行代码创建工作表目录列表后,如果又新建工作表或修改工作表名称,请再次运行代码。
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
独立显卡怎么安装?
![](https://img.aspxhome.com/file/2023/6/a326124_0s.jpg)
通过修改"簇"提高U盘性能的方法步骤介绍
![](https://img.aspxhome.com/file/2023/3/a295821_0s.jpg)
Win10使用“解锁电脑”代替登录名的方法
![](https://img.aspxhome.com/file/2023/5/a316025_0s.jpg)
Windows10无法访问指定设备文件的操作详细解决步骤
![](https://img.aspxhome.com/file/2023/1/a280536_0s.png)
excel表格中使用自动计算的教程
Win7系统不能上网解决方法
![](https://img.aspxhome.com/file/2023/1/a281136_0s.jpg)
mbm4.exe是什么进程 mbm4进程查询
Win10用文件夹右键属性后消失怎么办?Win10在用户文件夹右键属性后消失的找回方法
![](https://img.aspxhome.com/file/2023/9/49029_0s.png)
keylogger是什么进程
![](https://img.aspxhome.com/file/2023/6/a320428_0s.jpg)
QQ影音怎么压缩视频文件?QQ影音压缩视频文件的方法
![](https://img.aspxhome.com/file/2023/8/a333933_0s.jpg)
夜神模拟器怎么导出文件到电脑?夜神模拟器导出文件到电脑的方法
![](https://img.aspxhome.com/file/2023/7/a328167_0s.jpg)
智能ABC输入法的一些妙用
哔哩哔哩怎么关闭青少年模式?哔哩哔哩关闭青少年模式的方法
![](https://img.aspxhome.com/file/2023/8/a333554_0s.jpg)
win10电脑如何合理设置虚拟内存?
![](https://img.aspxhome.com/file/2023/4/a305253_0s.gif)
Win8开机弹出RunDLL错误提示的解决方法
![](https://img.aspxhome.com/file/2023/3/a298955_0s.jpg)
WPS 如何在word文档中拆分表格
![](https://img.aspxhome.com/file/2023/9/a187179_0s.jpg)
WPS2016如何插入页眉和页脚
![](https://img.aspxhome.com/file/2023/8/a170178_0s.jpg)
自己重装Win7系统怎么弄?Win7系统装机步骤图解
![](https://img.aspxhome.com/file/2023/26/a227923_0s.png)
WinRAR软件如何层叠右键关联菜单
![](https://img.aspxhome.com/file/2023/9/a341220_0s.png)
Win10出现Werfault.exe应用程序错误如何解决?
![](https://img.aspxhome.com/file/2023/26/a224683_0s.jpg)