Auto hide sheets

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hello

Basic and simple question, but have forgotten.

How do you hide any open sheets, when opening a workbook?

Thanks
 
Hello tcbootneck,

Add the following code to your Workbook's Open event procedure.

Dim Wks As Worksheet
For Each Wks In ThisWorkbook.Worksheets
If Wks.Visible = xlSheetVisible Then Wks.Visible = xlSheetHidden
Next Wks

This will check each Worksheet and test if it is visible. If it is
visible then the macro will hide the Worksheet. Your final code result
will look like this...

Private Sub Workbook_Open()
Dim Wks As Worksheet
For Each Wks In ThisWorkbook.Worksheets
If Wks.Visible = xlSheetVisible Then Wks.Visible = xlSheetHidden
Next Wks
End Sub

Sincerely,
Leith Ross
 
Don't you get an error or am I missing something? I don't think you can hide
all worksheets at the same time. I assumed Leith had an oversight. Thought it
should be something like:

Private Sub Workbook_Open()
Dim Wks As Worksheet
For Each Wks In ThisWorkbook.Worksheets
If Wks.Name <> "Sheet1" Then
If Wks.Visible = xlSheetVisible Then Wks.Visible = xlSheetHidden
End If
Next Wks
End Sub

Greg
 
A workbooks MUST have one visible sheet, either a Sheet or a Worksheet.
 
I take that as a confirmation. Perhaps tcbootneck has a chart sheet and so
didn't get an error?

Greg
 
Hi Leith

I am really new to VBA Programming, and seems to struggling with connecting
the dots at this point.

The macro works really well, but I was wondering if I could add exclusionary
criteria. I want the Macro to ignore a specific sheet when it is going
through the 15 sheets in workbook.


Thanks

John
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top