Excel 如何超链接到同一工作表中的多个隐藏选项卡?
我有一个指向工作簿中多个不同隐藏工作表的超链接列表,每个超链接使用以下内容:Excel 如何超链接到同一工作表中的多个隐藏选项卡?,excel,vba,Excel,Vba,我有一个指向工作簿中多个不同隐藏工作表的超链接列表,每个超链接使用以下内容: Private Sub Worksheet_FollowHyperlink(ByVal Target As Hyperlink) Application.ScreenUpdating = False Worksheets("LL - JLL").Visible = xlSheetVisible Sheets("LL - JLL").Visible = Tr
Private Sub Worksheet_FollowHyperlink(ByVal Target As Hyperlink)
Application.ScreenUpdating = False
Worksheets("LL - JLL").Visible = xlSheetVisible
Sheets("LL - JLL").Visible = True
Sheets("LL - JLL").Select
Application.ScreenUpdating = True
End Sub
据我所知,这适用于工作表上的每个超链接。每个超链接现在都指向相同的工作表,LL-JLL
,而我需要每个超链接指向不同的工作表。比如说,
Private Sub Worksheet_FollowHyperlink(ByVal Target As Hyperlink)
Application.ScreenUpdating = False
Worksheets("LL - JLL").Visible = xlSheetVisible
Sheets("LL - JLL").Visible = True
Sheets("LL - JLL").Select
Application.ScreenUpdating = True
Application.ScreenUpdating = False
Worksheets("LL - EMS").Visible = xlSheetVisible
Sheets("LL - EMS").Visible = True
Sheets("LL - EMS").Select
Application.ScreenUpdating = True
Application.ScreenUpdating = False
Worksheets("LL- CCURE").Visible = xlSheetVisible
Sheets("LL- CCURE").Visible = True
Sheets("LL- CCURE").Select
Application.ScreenUpdating = True
End Sub
以下代码使工作表上的所有超链接指向LL-CURE
工作表,而不是对应的工作表
为不同的超链接创建新子链接将导致
Compile error:
Ambiguous name detected: Worksheet_FolowHyperlink
非常感谢您的指导:)逻辑:
Option Explicit
Private Sub Worksheet_FollowHyperlink(ByVal Target As Hyperlink)
Dim rng As Range
'~~> Get the range the hyperlink is referrig to
Set rng = Application.Evaluate(Target.SubAddress)
'~~> Unhide and activate the sheet
UnHideAndActivate rng.Parent.Name
End Sub
Private Sub UnHideAndActivate(shName As String)
Dim scrnUpdating As Boolean
Dim dsplyAlerts As Boolean
On Error GoTo Whoa
With Application
'~~> Get user's current setting
scrnUpdating = .ScreenUpdating
dsplyAlerts = .DisplayAlerts
'~~> Set it to necessary setting
.ScreenUpdating = False
.DisplayAlerts = False
End With
'~~> Unhide and activate the sheet
Worksheets(shName).Visible = xlSheetVisible
Worksheets(shName).Activate
LetsContinue:
With Application
'~~> Reset original settings
.ScreenUpdating = scrnUpdating
.DisplayAlerts = dsplyAlerts
End With
Exit Sub
Whoa:
MsgBox Err.Description
Resume LetsContinue
End Sub
阅读这种结构清晰的代码是一种乐趣:+)谢谢@T.M.我总是缩进我的代码和leevae注释,以便更容易阅读和理解:)