ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   How do I Hide VBA excel sheets after saving (https://www.excelbanter.com/excel-programming/439245-how-do-i-hide-vba-excel-sheets-after-saving.html)

Burltree

How do I Hide VBA excel sheets after saving
 
How do I return to hidding VBA excel sheets after saving changes to an exel
sheet?

Don Guillett[_2_]

How do I Hide VBA excel sheets after saving
 
Are you using xl95?

--
Don Guillett
Microsoft MVP Excel
SalesAid Software

"Burltree" wrote in message
...
How do I return to hidding VBA excel sheets after saving changes to an
exel
sheet?



Ryan H

How do I Hide VBA excel sheets after saving
 
Put this in your Workbook BeforeSave Event. This code will loop through a
collection of worksheets that you specify and hide them. Just change the
sheet names to fit your application.

Note: At least one sheet in the workbook must be visible at ALL times or
VBA will throw an error. Plus, do you want the sheets "Hidden" or "Very
Hidden"?

"Hidden" will allow users to unhide work sheets by right clicking the sheets
tabs at the bottom left and selecting the sheet they want to unhide.

"Very Hidden" will only allow the sheet to become unhidden through code
using VBA.

Hope this helps! If so, let me know, click "YES" below.

Option Explicit

Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean)

Dim colSheetsToHide As Collection
Dim wks As Worksheet

' collection of sheets to hide when workbook is saved
Set colSheetsToHide = New Collection
With colSheetsToHide
.Add Sheets("Sheet1")
.Add Sheets("Sheet2")
.Add Sheets("Sheet3")
End With

' hide worksheets in collection
For Each wks In colSheetsToHide
wks.Visible = False
Next wks

End Sub
--
Cheers,
Ryan


"Burltree" wrote:

How do I return to hidding VBA excel sheets after saving changes to an exel
sheet?



All times are GMT +1. The time now is 04:43 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com