Hide worksheets on close

bakerman

Board Regular
Joined
Sep 9, 2005
Messages
188
How do I hide all worksheets in a workbook when the workbook is being closed so that the next time it is opened only sheet 1 (named TOC ) is visable
 

Excel Facts

What is the shortcut key for Format Selection?
Ctrl+1 (the number one) will open the Format dialog for whatever is selected.
Use the Macro Recorder to record a macro that hides all the sheets except TOC. Copy the macro (excluding the first and last lines) to the clipboard.

In the "This sheet" module, paste this:
Code:
Private Sub Workbook_BeforeClose(Cancel As Boolean)

End Sub

Paste your recorded macro in between the first and last lines.

Save the workbook. When you close the workbook, the macro will hide the desired sheets.
 
Upvote 0
Good afternoon bakerman

Further to Barry's answer use this code between his suggested opening / closing lines :

Code:
On Error Resume Next
For Each wksht In ActiveWorkbook.Worksheets
If Not wksht.Name = "TOC" Then Sheets(wksht.Name).Visible = False
Next wksht

To show sheets again make .Visible=False.
For extra security you could use .Visible=xlVeryHidden. This would stop the sheets being listed in the Format > Sheet > Unhide dialog. Just stops users not savvy enough to know better poking their noses into bits they're not supposed to.

HTH

DominicB
 
Upvote 0

Forum statistics

Threads
1,226,223
Messages
6,189,719
Members
453,566
Latest member
ariestattle

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