Use VBA to Open and Hide Dynamically Named Excel Sheets
Question details
Open dynamically named hidden worksheets from a master sheet and hide them again when returning.

- Product
- Microsoft Excel
- Device & OS
- not provided
- Scenario
- A master sheet contains links to hidden worksheets, and each destination sheet has a link back to the master sheet.
- Observed behavior
- The user needs navigation that reveals the selected destination and hides it after returning to the master sheet.
Save the workbook as an Excel Macro-Enabled Workbook (.xlsm), and enable macros when prompted in desktop Excel. Confirm that the master sheet is named Master, that links use current sheet names, and that workbook structure protection does not prevent changing sheet visibility.
Handle worksheet hyperlinks in the ThisWorkbook module
Use a workbook-level event to reveal linked sheets and hide a source sheet after a link returns to Master.
The procedure handles internal hyperlinks whose SubAddress identifies a worksheet and cell in the same workbook. It reads the sheet name from each link rather than relying on a fixed destination name.
Excel may not fire the follow-hyperlink event if it cannot follow a link to a hidden sheet. Test the links in your workbook; if the event does not run, use the button-based solution instead.
Open the VBA editor in desktop Excel, find your workbook in Project Explorer, and double-click ThisWorkbook.
Paste this code into ThisWorkbook. If a Workbook_SheetFollowHyperlink procedure already exists, integrate the logic into that procedure rather than adding a duplicate: Private Sub Workbook_SheetFollowHyperlink(ByVal Sh As Object, ByVal Target As Hyperlink) Dim address As String, sheetName As String, cellAddress As String Dim separator As Long Dim destination As Worksheet Dim destinationCell As Range On Error GoTo Failed If TypeName(Sh) <> "Worksheet" Then Exit Sub address = Target.SubAddress separator = InStrRev(address, "!") If separator = 0 Then Exit Sub sheetName = Left$(address, separator - 1) cellAddress = Mid$(address, separator + 1) If Left$(sheetName, 1) = "'" And Right$(sheetName, 1) = "'" Then sheetName = Mid$(sheetName, 2, Len(sheetName) - 2) sheetName = Replace(sheetName, "''", "'") End If Set destination = ThisWorkbook.Worksheets(sheetName) Set destinationCell = destination.Range(cellAddress) If Sh.Name <> "Master" And destination.Name <> "Master" Then Exit Sub destination.Visible = xlSheetVisible destination.Activate destinationCell.Select If Sh.Name <> "Master" And destination.Name = "Master" Then Sh.Visible = xlSheetHidden End If Exit Sub Failed: MsgBox "Could not open the linked sheet. Check the link and workbook protection.", vbExclamation End Sub
Save the workbook, click a link on Master to a hidden sheet, and then click that sheet's return link to Master. Verify that the destination opens and is hidden after you return.

Use assigned macros to open and hide sheets
Use buttons instead of hyperlinks when Excel cannot follow a link to a hidden worksheet.
Work with Excel spreadsheets in WPS Office
WPS Office is a free, lightweight alternative with a familiar spreadsheet interface and support for common Excel formats, making it easy to move everyday spreadsheet work. Use Microsoft Excel to implement and test the VBA event solution described above.

Frequently Asked Questions
Where should I put the hyperlink event code?
In the VBA editor, double-click ThisWorkbook under your workbook in Project Explorer and place the Workbook_SheetFollowHyperlink procedure there.
Why doesn't a hyperlink open my hidden sheet?
Excel may fail to follow the link before the event can run. Check that the link's SubAddress contains the current sheet name; if the event still does not fire, use the assigned-macro buttons instead.
Will the event update links when sheet names change?
No. The event reads the destination stored in the hyperlink. Update the link's SubAddress when a sheet is renamed, or use the button method with a cell containing the current sheet name.
Why can't the macro hide a sheet?
Workbook structure protection can prevent visibility changes. In Excel, check Review > Protect Workbook and remove structure protection if you have permission. Excel must also keep at least one worksheet visible.




