Hi
My intentions is to prevent the workbook from being used if the macros are not enabled. If the workbook macros are not enabled then a warning is displayed and hiding all other sheets and instructing the user to close and re-open the workbook and enable the macros.
I am getting a Run-time error '1004' on exit and start up "Unable to set the Visible property of the Sheets class"
When I Debug, the highlighted area that is identified is the Sheet Array section for both private subs.
This is what I have at the minute.
Private Sub Workbook_BeforeClose(Cancel As Boolean)
' Turn off Screen Updating
Application.ScreenUpdating = False
'Unlock Workbook
ActiveWorkbook.Unprotect Password:="XXXXX"
'Unlock Sheets
Dim wsWorksheet As Worksheet
For Each wsWorksheet In ActiveWorkbook.Worksheets
wsWorksheet.Unprotect Password:="XXXXX"
Next
'Unhide Sheet
Sheets("Warning").Visible = True
'Hide Sheets
Sheets(Array("SMU HR Meter Entry", "Service Schedule", _
"Ancillary Schedule", "Light Vehicle Schedule", "Oil Sampling Schedule", _
"Drifter Percussion Hours", "Project 32 Valve Sets", " EOM HRS Data", _
"Schedule Major Service Table", "Master Sheet")).Visible = xlVeryHidden
'Lock Sheets
For Each wsWorksheet In ActiveWorkbook.Worksheets
wsWorksheet.Protect Password:="XXXXX"
Next
'Turn on Screen Updating
Application.ScreenUpdating = True
'Lock Workbook
ActiveWorkbook.Protect Password:="XXXXX"
End Sub
Private Sub Workbook_Open()
' Turn off Screen Updating
Application.ScreenUpdating = False
'Unlock Workbook
ActiveWorkbook.Unprotect Password:="XXXXX"
'Unlock Sheets
Dim wsWorksheet As Worksheet
For Each wsWorksheet In ActiveWorkbook.Worksheets
wsWorksheet.Unprotect Password:="XXXXX"
Next
'Unhide Sheets
Sheets(Array("SMU HR Meter Entry", "Service Schedule", _
"Ancillary Schedule", "Light Vehicle Schedule", "Oil Sampling Schedule", _
"Drifter Percussion Hours", "Project 32 Valve Sets", " EOM HRS Data", _
"Schedule Major Service Table", "Master Sheet")).Visible = True
'Hide Sheet
Sheets("Warning").Visible = xlVeryHidden
'Lock Sheets
For Each wsWorksheet In ActiveWorkbook.Worksheets
wsWorksheet.Protect Password:="XXXXX"
Next
'Lock Workbook
ActiveWorkbook.Protect Password:="XXXXX"
'Turn on Screen Updating
Application.ScreenUpdating = True
End Sub
P.S. I'm new, self taught and have been at this for no longer than 4 weeks.............be gentle!
P.S.S. Note attached file is my test file, this is not my master.
Cheers
Bookmarks