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

Select a hidden cell
Somehide hide payroll data in column G? Press F5. Type G1. Enter. Look in formula bar while you arrow down through G.
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,223,214
Messages
6,170,771
Members
452,353
Latest member
strainu

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