How to xlVeryHide Sheet on workBook Close

HotNumbers

Well-known Member
Joined
Feb 14, 2005
Messages
732
How do I Very Hide a worksheet on close? I have VB that is run that unhide worksheets I want the ability to automatically very hide specific sheets if they are left visible?
 

Excel Facts

Get help while writing formula
Click the italics "fx" icon to the left of the formula bar to open the Functions Arguments dialog. Help is displayed for each argument.
i need the code to run on workbook close. I have other VB that hides and unhides sheets; however, i need to have the ability to hide sheets if a sheet is left unhidden during close.
 
Upvote 0
Try if this works
Code:
Private Sub Workbook_BeforeClose(Cancel As Boolean)
    Dim i As Long
    For i = 1 To Worksheets.Count
        If Worksheets(i).Visible = -1 Then
            Worksheets(i).Visible = 2
        End If
    Next i
End Sub

It hides all the sheets to very hidden if it is shown.
 
Upvote 0
I appreciate your help...
But it is not what i am looking for. For example I have sheet called Master Table. Should a user have this sheet visiable I want the ability to close the sheet upon workbook close. In other words I do not want the Master Table sheet to be visiable next time the file is opened.
 
Upvote 0
I think you can tweak the code a little to fit your needs.
I'm having a hard time understanding because first you wanted "sheets" to be very hidden upon close. and now you want a sheet named "Master Table" that needs to be hidden.

Anyways, this is my interpretation of your problem:
You want to set Master Table sheet to be very hidden upon closing.
Code:
Private Sub Workbook_BeforeClose(Cancel As Boolean)
    Application.DisplayAlerts = False
    Worksheets("Master Table").Visible = xlSheetVeryHidden
    ThisWorkbook.Save
    Application.DisplayAlerts = True
End Sub
 
Upvote 0

Forum statistics

Threads
1,224,521
Messages
6,179,277
Members
452,902
Latest member
Knuddeluff

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