VBA & Macro Problems

Open and Automatically Hide a Worksheet in Excel

Aamir Naveed AkramAamir Naveed Akram Nov 25, 2026 868 views

Question details

Open hidden worksheets from a summary sheet and automatically hide them when users leave or close the workbook.

How to Open and Automatically Hide a Worksheet in Excel
Product
Microsoft Excel
Device & OS
not provided
Scenario
A summary sheet provides access to worksheets that should otherwise remain hidden.
Observed behavior
Users should be able to open a hidden worksheet and have it hidden again after leaving it or closing the workbook.
Before you start

Use desktop Excel, save the workbook as an Excel Macro-Enabled Workbook (.xlsm), and enable macros when prompted. Keep the summary sheet visible and make sure the workbook structure is not protected against changes to sheet visibility.

Solution 1Recommended

Use VBA to open and automatically hide a worksheet

Use a macro-enabled shape on the summary sheet to open the hidden worksheet, then use worksheet and workbook events to hide it again.

A normal hyperlink cannot unhide a hidden worksheet before navigating to it. A shape assigned to a macro provides a clickable alternative.

The example uses sheets named Summary and Sheet2. Replace these names with the exact worksheet tab names in your workbook.

1
Add the opening macro

Open the Visual Basic Editor from Developer > Visual Basic. Select your workbook, choose Insert > Module, and add: Sub OpenSheet2() With ThisWorkbook.Worksheets("Sheet2") .Visible = xlSheetVisible .Activate End With End Sub

2
Assign the macro to a shape

On the Summary sheet, choose Insert > Shapes and add a shape labeled for Sheet2. Right-click the shape, choose Assign Macro, select OpenSheet2, and click OK.

3
Hide the sheet when users leave

In the Visual Basic Editor, double-click Sheet2 under Microsoft Excel Objects and add: Private Sub Worksheet_Deactivate() Me.Visible = xlSheetHidden End Sub

4
Hide the sheet when the workbook closes

Double-click ThisWorkbook under Microsoft Excel Objects and add: Private Sub Workbook_BeforeClose(Cancel As Boolean) ThisWorkbook.Worksheets("Summary").Activate ThisWorkbook.Worksheets("Sheet2").Visible = xlSheetHidden End Sub

5
Test and save

Return to Excel, click the shape on Summary, and verify that Sheet2 opens. Select Summary to confirm that Sheet2 hides, then save the workbook; when closing, save any prompted changes to retain the hidden state.

Use VBA to open and automatically hide a worksheet
Repeat for additional sheets: For each additional sheet, add a separate opening macro and shape, place the Worksheet_Deactivate event in that sheet's module, and add a Visible = xlSheetHidden line for it in Workbook_BeforeClose. Keep at least one worksheet visible.
Free Microsoft Office alternative

Manage spreadsheets with 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 workbook work. The Excel VBA event solution above is specific to Microsoft Excel.

View and manage worksheet tabs in WPS SpreadsheetsOpen and edit common Microsoft Excel formats, including XLSXWork in a familiar interface that makes migration easierUse a free, lightweight office suite for everyday documents
microsoft office alternative - wps office

Frequently Asked Questions

Can an Excel hyperlink open a hidden worksheet directly?

A normal hyperlink does not unhide a worksheet before navigating to it. Instead, insert a shape on the summary sheet and use right-click > Assign Macro to run a macro that makes the sheet visible and activates it.

Where should I put the Worksheet_Deactivate code?

In Developer > Visual Basic, double-click the target worksheet under Microsoft Excel Objects and paste the event procedure into that worksheet's code module.

Why does Excel not hide the worksheet when I leave it?

Check that macros are enabled, the Worksheet_Deactivate code is in the correct worksheet module, and workbook structure protection is not preventing visibility changes. Also keep another worksheet visible.

Will the sheet remain hidden after I close the workbook?

The Workbook_BeforeClose event can hide it, but the hidden state must be saved. If Excel prompts you to save changes when closing, choose Save.