How to Hide and Unhide Worksheet in Excel VBA?

In this post, you’ll will learn about some tips and tricks on how to hide and unhide worksheet using Excel VBA.

Hide Sheet in VBA

To hide a Sheet in Excel VBA, Set the Visible property to FALSE.

Code:

Worksheets("Sheet1").visible = False

or

Worksheets("Sheet1").visible = xlSheetHidden
How to Hide and Unhide Worksheet in Excel VBA?

Unhide Sheet

To unhide a Sheet in VBA,

Code:

Worksheets("Sheet1").Visible = True

or

Worksheets("Sheet1").Visible = xlSheetVisible
How to Hide and Unhide Worksheet in Excel VBA?

Very Hidden Sheets

The xlSheetVeryHidden property,

Code:

Worksheets("Sheet1").Visible = xlSheetVeryHidden

Unhide Very Hidden Sheets

To unhide very hidden sheets.

Code:

Worksheets("Sheet1").Visible = True

or

Worksheets("Sheet1").Visible = xlSheetVisible

Hide and Unhide Sheets in the VBA Editor

You can also toggle the Worksheet Visible property within the VBA Editor:

Hide and Unhide Sheets in Protected Workbook

To hide or unhide sheets in a protected workbook, you need to unprotect it first.

Code:

 ActiveWorkbook.Unprotect

If it is password protected, then

Code:

ThisWorkbook.Unprotect "password"

Now you can unhide all the hidden sheets.

Unhide All Sheets

Using for each loop, you can unhide all sheets in a workbook.

Code:

Sub Unhide_Sheets_VBAEditor()

    Dim ws As Worksheet

   ActiveWorkbook.Unprotect

    For Each ws In Worksheets

        ws.Visible = xlSheetVisible

    Next

End Sub