Hi, I have a seemingly simple problem but I can't seem to get around it. Perhaps someone else could enlighten me. When the user closes the workbook, I would like all worksheets except Inputs, SummaryOutput and DetailedOutput to be hidden. My attempt at the code is below:
Private Sub Workbook_BeforeClose(Cancel As Boolean)
Dim ws As Worksheet
Application.EnableEvents = True
For Each ws In ActiveWorkbook.Worksheets
If Not ws.Name = "Inputs" Or Not ws.Name = "SummaryOutput" Or Not ws.Name = "DetailedOutput" Then
ws.Visible = xlSheetHidden
End If
Next ws
ThisWorkbook.Save
End Sub
It's giving me a runtime error 1004- any ideas why? Any help would be greatly appreciated!
Bookmarks