Auto-hiding sheets AND charts [code needs a tweak]

Grizlore

Active Member
Joined
Aug 22, 2006
Messages
259
Hi All,

The code below works fine, apart from it will not hide charts, only sheets.

Upon closing, I need to hide everything (sheet and charts) and just leave "LOCKED" on display. When it opens, I need to see everything except "LOCKED"

Could anyone tell me the most efficient way to amend the code below to accomodate this please?

Code:
Option Explicit

Sub Auto_close()
Dim wsSheet As Worksheet

Application.ScreenUpdating = False

For Each wsSheet In ThisWorkbook.Worksheets
    If wsSheet.Name = "LOCKED" Then
     wsSheet.Visible = xlSheetVisible
    Else
     wsSheet.Visible = xlSheetVeryHidden
    End If
Next wsSheet
    ActiveWorkbook.Save

Application.ScreenUpdating = True

End Sub

'/////////////////////////////////

Sub Auto_open()

Application.ScreenUpdating = False
    
   Dim wsSheet As Worksheet
For Each wsSheet In ThisWorkbook.Worksheets
    If wsSheet.Name <> "LOCKED" Then
     wsSheet.Visible = xlSheetVisible
    End If
Next wsSheet

Sheets("LOCKED").Visible = xlSheetVeryHidden

  Application.ScreenUpdating = True
  
End Sub


Suggestions appreciated !
 

Excel Facts

Difference between two dates
Secret function! Use =DATEDIF(A2,B2,"Y")&" years"&=DATEDIF(A2,B2,"YM")&" months"&=DATEDIF(A2,B2,"MD")&" days"
Try looping around ThisWorkbook.Sheets instead of ThisWorkbook.Worksheets. You will need to declare wsSheet as Object.
 
Upvote 0

Forum statistics

Threads
1,224,598
Messages
6,179,814
Members
452,945
Latest member
Bib195

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