跳到主要内容

如何跟随超链接到Excel中的隐藏工作表?

例如,我有一个包含多个工作表的工作簿,第一个主工作表具有指向其他工作表的超链接,现在,我隐藏了除第一个工作表以外的所有工作表。 在这种情况下,链接到隐藏工作表的超链接不可用。 但是,如何使这些超链接成功工作? 当您单击一个超链接时,链接的隐藏工作表将立即打开,如以下屏幕截图所示:

doc超链接到隐藏工作表1

按照超链接打开带有VBA代码的隐藏工作表

按照超链接打开隐藏的工作表,然后使用VBA代码再次将其隐藏


按照超链接打开带有VBA代码的隐藏工作表

下面的VBA代码可以帮助您在单击隐藏的工作表的相对超链接时打开它,请按以下步骤操作:

1。 右键单击要跟随超链接到隐藏工作表的工作表选项卡,然后选择 查看代码 从上下文菜单中,弹出 Microsoft Visual Basic应用程序 窗口,请将以下代码复制并粘贴到空白模块中:

VBA代码:按照超链接打开隐藏的工作表:

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
'Updateby Extendoffice
    Application.ScreenUpdating = False
    On Error Resume Next
    If Target.Column = 1 Then
        Sheets(Target.Value).Visible = xlSheetVisible
        Sheets(Target.Value).Select
    End If
    Application.ScreenUpdating = True
End Sub

doc超链接到隐藏工作表2

备注:在上面的代码中,数字 1 摘要可点击此连结 如果Target.Column = 1然后 脚本指示包含超链接的列号,请根据需要进行更改。

2。 然后保存并关闭此代码窗口,现在,单击链接到特定隐藏工作表的超链接时,隐藏工作表将立即打开。


按照超链接打开隐藏的工作表,然后使用VBA代码再次将其隐藏

有时,您需要遵循超链接来打开隐藏的工作表,而当您返回主工作表时,您希望再次隐藏已打开的工作表。 下面的VBA代码可以帮您一个忙:

1。 右键单击要跟随超链接到隐藏工作表的工作表选项卡,然后选择 查看代码 从上下文菜单中,弹出 Microsoft Visual Basic应用程序 窗口,请将以下代码复制并粘贴到空白模块中:

VBA代码:当再次返回将其隐藏时,请按照超链接打开隐藏的工作表:

Private Sub Worksheet_FollowHyperlink(ByVal Target As Hyperlink)
   'Updateby Extendoffice
    Application.ScreenUpdating = False
    Dim strLinkSheet As String
    If InStr(Target.Parent, "!") > 0 Then
        strLinkSheet = Left(Target.Parent, InStr(1, Target.Parent, "!") - 1)
    Else
        strLinkSheet = Target.Parent
    End If
    Sheets(strLinkSheet).Visible = True
    Sheets(strLinkSheet).Select
    Application.ScreenUpdating = True
End Sub

Private Sub Worksheet_Activate()
    On Error Resume Next
    Sheets(ActiveCell.Value2).Visible = False
End Sub

doc超链接到隐藏工作表3

2。 然后保存广告代码窗口,当您单击超链接时,链接的隐藏工作表将立即打开,但是,如果您返回包含超链接的主工作表,则打开的工作表将再次被自动隐藏。

备注:这些代码仅应用于与您的超链接文本匹配的工作表名称。


演示:按照超链接打开带有VBA代码的隐藏工作表

Kutools for Excel:具有300多个方便的Excel加载项,可以在30天内免费试用,没有任何限制。 立即下载并免费试用!

最佳办公生产力工具

🤖 Kutools 人工智能助手:基于以下内容彻底改变数据分析: 智能执行   |  生成代码  |  创建自定义公式  |  分析数据并生成图表  |  调用 Kutools 函数...
热门特色: 查找、突出显示或识别重复项   |  删除空白行   |  合并列或单元格而不丢失数据   |   不使用公式进行四舍五入 ...
超级查询: 多条件VLookup    多值VLookup  |   跨多个工作表的 VLookup   |   模糊查询 ....
高级下拉列表: 快速创建下拉列表   |  依赖下拉列表   |  多选下拉列表 ....
列管理器: 添加特定数量的列  |  移动列  |  切换隐藏列的可见性状态  |  比较范围和列 ...
特色功能: 网格焦点   |  设计图   |   大方程式酒吧    工作簿和工作表管理器   |  资源库 (自动文本)   |  日期选择器   |  合并工作表   |  加密/解密单元格    按列表发送电子邮件   |  超级筛选   |   特殊过滤器 (过滤粗体/斜体/删除线...)...
前 15 个工具集12 文本 工具 (添加文本, 删除字符,...)   |   50+ 图表 类型 (甘特图,...)   |   40+ 实用 公式 (根据生日计算年龄,...)   |   19 插入 工具 (插入二维码, 从路径插入图片,...)   |   12 转化 工具 (小写金额转大写, 货币兑换,...)   |   7 合并与拆分 工具 (高级组合行, 分裂细胞,...)   |   ... 和更多

使用 Kutools for Excel 增强您的 Excel 技能,体验前所未有的效率。 Kutools for Excel 提供了 300 多种高级功能来提高生产力并节省时间。  单击此处获取您最需要的功能...

产品描述


Office Tab 为 Office 带来选项卡式界面,让您的工作更加轻松

  • 在Word,Excel,PowerPoint中启用选项卡式编辑和阅读,发布者,Access,Visio和Project。
  • 在同一窗口的新选项卡中而不是在新窗口中打开并创建多个文档。
  • 每天将您的工作效率提高50%,并减少数百次鼠标单击!
Comments (9)
No ratings yet. Be the first to rate!
This comment was minimized by the moderator on the site
Not sure if I will get a response to this one, but when I click the any of my hyperlinks I get a "reference isn't valid" error.
Everything still works, I just need to click ok to continue.
Does anyone have an idea what causes this error for this code?
Thank you,
This comment was minimized by the moderator on the site
I have created many wordbook and I want to index those in one page.

N.B: My point is I want to hide all the sheets, the sheets will linked with setting picture to main page. By clicking the picture linked sheet will be shown and when I come back to the main sheet the un-hide sheet will be hidden again
This comment was minimized by the moderator on the site
I would like to use this code but only want it to apply to column A. I have other web address links in other cells which cause a problem when running this code.
This comment was minimized by the moderator on the site
My hyperlink "text" is number only, and it doesn't work...
This comment was minimized by the moderator on the site
I'm using the code on two different sheets. It works for one of about 40 hyperlinks on one sheet and it opens two of about 10 hyperlinks one she second, the sheets on the second which do open do go back into hiding when I return to the sheet. The error I get when it will not open a sheet is Run-time error"9": script out of range and the code it points me to - Sheets(strLinkSheet).Visible = True Any ideas as to what change is needed make the code work on all of the sheets? Thank you in advance.
This comment was minimized by the moderator on the site
I have used this code on two different sheets in my workbook, and in both cases it works great, except for the first hyperlink on each page. I get "Subscript out of range error" and the debugger points to the "Sheets(strLinkSheet).Visible = True" right after the "end if". Anyone else see this error? It is only on the first link on the page. (my hyperlinks are in column A, and start in row 2)
This comment was minimized by the moderator on the site
[quote]I have used this code on two different sheets in my workbook, and in both cases it works great, except for the first hyperlink on each page. I get "Subscript out of range error" and the debugger points to the "Sheets(strLinkSheet).Visible = True" right after the "end if". Anyone else see this error? It is only on the first link on the page. (my hyperlinks are in column A, and start in row 2)By HelzBelz[/quote] Sheet names can't have space like "Sheet 1". I fixed my sheet names to "Sheet1" and the error stopped.
This comment was minimized by the moderator on the site
I have a sheet that is hidden that contains a hyperlink. I would like to be able go to the hidden sheet and have it close when I go back to the original sheet. I used the code but it does not work.
This comment was minimized by the moderator on the site
I am trying to hide a sheet that has a hyperlink. I would like to be able to click on the sheet go to the hyperlink sheet and then click back to the sheet and close the hidden sheet. I have tried your instructions but it does not work. Not sure what I am doing wrong.
There are no comments posted here yet
Please leave your comments in English
Posting as Guest
×
Rate this post:
0   Characters
Suggested Locations