VBA to hide all but one sheet on open

TonemanABC

New Member
Joined
Apr 11, 2024
Messages
1
Office Version
  1. 2021
Platform
  1. Windows
Very new to VBA so excuse my ignorance. Trying to design a simple spreadsheet using forms to enter data on separate spreadsheets. I only want the 'Menu' spreadsheet to display when opening the workbook. I also have code linked to the buttons on my menu spreadsheet to open the pages.

I am using the code

VBA Code:
Private Sub Workbook_Open()

Dim b As Worksheet

For Each b In Worksheets
    If b.Name <> "Menu" Then b.Visible = False
Next b

End Sub

However whilst this works fine - it seems to be set to a loop? And none of my other buttons seem to be working.

Is there better code to do this?
 

Excel Facts

How to show all formulas in Excel?
Press Ctrl+` to show all formulas. Press it again to toggle back to numbers. The grave accent is often under the tilde on US keyboards.
Try on a copy.
VBA Code:
Private Sub Workbook_Open()
    Dim ws As Worksheet
    Application.ScreenUpdating = False

    ' Hide all sheets except the "Menu" sheet
    For Each ws In ThisWorkbook.Worksheets
        If ws.Name <> "Menu" Then
            ws.Visible = xlSheetHidden ' or xlSheetVeryHidden if you want to completely hide the sheets
        End If
    Next ws

    Application.ScreenUpdating = True
End Sub
 
Upvote 0

Forum statistics

Threads
1,215,375
Messages
6,124,576
Members
449,174
Latest member
chandan4057

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