open hidden sheet with dynamic hyperlink

mctown

New Member
Joined
Feb 24, 2022
Messages
4
Office Version
  1. 2021
Platform
  1. Windows
Hello,

Am new here and I don't know if I should create a new thread but my question is related to dynamic hyperlinks.
Anyways, I created a dynamic hyperlink that can jump to desired sheet based on the sheet name. It works fine. The issue is that the dynamic hyperlink won't work if sheet are hidden.

I have tried the VBA codes on YouTube: Learn Excel from MrExcel - "Hyperlink to a Hidden Worksheet" - Podcast #1729

It only works if sheet hyperlink is created using "Ctrl K" process.

Would appreciate any help.

Thanks in advance!

dynamic-hyperlink.xlsx
ABC
2Type sheet name here ->sheet1sheet1
3
4Sheets Names
5sheet1active
6sheet2hidden
main
Cell Formulas
RangeFormula
C2C2= HYPERLINK("#" &B2& "!A3",B2)
Cells with Conditional Formatting
CellConditionCell FormatStop If True
B2:C2Cell Value=0textNO
Cells with Data Validation
CellAllowCriteria
B2List=#REF!#
 

Excel Facts

Format cells as currency
Select range and press Ctrl+Shift+4 to format cells as currency. (Shift 4 is the $ sign).
I remember coming up with a hacky workaround. Take a look and see if that helps :
 
Upvote 0
I remember coming up with a hacky workaround. Take a look and see if that helps :
Hi Jaafar,
Thanks for your reply. I used the codes but when I tried making the name of the sheet variable (i.e. sheet name = text contained in a reference cell). It doesn't work. Any help to resolve this would be appreciated. Thanks again.
 
Upvote 0
Try this variation :

Code goes in the ThisWorkbook Module:
VBA Code:
Option Explicit

Private WithEvents CmndBars As CommandBars

Private Type POINTAPI
    x As Long
    Y As Long
End Type

#If VBA7 Then
    Private Declare PtrSafe Function GetCursorPos Lib "user32.dll" (lpPoint As POINTAPI) As Long
    Private Declare PtrSafe Function GetKeyState Lib "user32" (ByVal nVirtKey As Long) As Integer
    Private Declare PtrSafe Function GetActiveWindow Lib "user32" () As LongPtr
#Else
    Private Declare Function GetCursorPos Lib "user32" (lpPoint As POINTAPI) As Long
    Private Declare Function GetKeyState Lib "user32" (ByVal nVirtKey As Long) As Integer
    Private Declare Function GetActiveWindow Lib "user32" () As Long
#End If


Private Sub Workbook_Activate()
    Set CmndBars = Application.CommandBars
    Call CmndBars_OnUpdate
End Sub

Private Sub Workbook_SheetSelectionChange(ByVal Sh As Object, ByVal Target As Range)
    Set CmndBars = Application.CommandBars
    Call CmndBars_OnUpdate
End Sub

Private Sub Workbook_BeforeClose(Cancel As Boolean)
    Set CmndBars = Nothing
End Sub


Private Sub CmndBars_OnUpdate()

    Static lPrev As Long
    Dim tCurPos As POINTAPI
    Dim oObj As Object, oTargetSheet As Worksheet
    Dim sFriendlyName As String, sTargetRangeAddr As String

    If Not ActiveWorkbook Is Me Or GetActiveWindow <> Application.Hwnd Then Exit Sub

    With Application
        Call GetCursorPos(tCurPos)
        Set oObj = .ActiveWindow.RangeFromPoint(tCurPos.x, tCurPos.Y)
        If TypeName(oObj) = "Range" And .ActiveWindow.RangeSelection.Count = 1 Then
            If InStr(1, oObj.Formula, "=HYPERLINK") Then
                If lPrev <> GetKeyState(VBA.vbKeyLButton) Then
                    sFriendlyName = Evaluate(oObj.Formula)
                    Set oTargetSheet = Worksheets(sFriendlyName)
                    If oTargetSheet.Visible <> xlSheetVisible Then
                        oTargetSheet.Visible = xlSheetVisible
                        Application.Goto oTargetSheet.Range("a1"), True
                    End If
                End If
            End If
        End If
    End With
    lPrev = GetKeyState(VBA.vbKeyLButton)
End Sub
 
Last edited:
Upvote 0

Forum statistics

Threads
1,223,903
Messages
6,175,289
Members
452,631
Latest member
a_potato

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top