How to unhide all sheets in a workbook using VBA?

To unhide all sheets in a workbook using VBA, you can create a simple macro. VBA (Visual Basic for Applications) is a programming language in Microsoft Excel that allows you to automate tasks. Here’s a step-by-step guide to unhide all sheets:

     Sub UnhideAllSheets()
         Dim ws As Worksheet
         For Each ws In ThisWorkbook.Sheets
             ws.Visible = xlSheetVisible
         Next ws
     End Sub
  • Open the Excel Workbook: Start by opening the Excel workbook where you want to unhide all sheets.
  • Open the VBA Editor:
    • Press `ALT` + `F11` to open the Visual Basic for Applications editor.
  • Insert a New Module:
    • Right-click on any of the objects for your workbook in the “Project Explorer” pane. If the “Project Explorer” is not visible, press `CTRL` + `R` to show it.
    • Click on “Insert” and then select “Module”. This will create a new module where you can write your VBA code.
  • Write the VBA Code:
    • Copy and paste the following VBA code into the module window:
  • Run the Macro:
    • You can run this macro directly from the VBA editor by pressing `F5` or you can close the VBA editor and run it from Excel by going to the “Developer” tab, clicking on “Macros”, selecting `UnhideAllSheets`, and clicking “Run”.
  • Ensure Macros Are Enabled:
    • Make sure macros are enabled in your Excel settings, otherwise, the macro will not run.

This macro loops through all sheets in the active workbook and sets their `Visible` property to `xlSheetVisible`, effectively unhiding them. Remember that this will not unhide sheets that are “Very Hidden”, which you can set in the VBA editor itself but are rare in normal Excel workbooks.

Unlock Your Potential

Excel

Basic - Advanced

Access

Access Basic - Advanced

Power BI

Power BI Basic - Advanced

Help us grow the project