That happens because your code cannot change the sheets' properties if you have your workbook protected. To avoid that error try to write the following code:
Code to the opening of the file
Dim i As Integer
Dim pass, page As String
pass = "the password you've set for the workbook protection"
page = "the name of your warning page"
Application.EnableCancelKey = xlDisabled
ActiveWorkbook.Unprotect Password:=pass
For i = 1 To ThisWorkbook.Worksheets.Count
' Skip empty sheets And hidden sheets
If ThisWorkbook.Worksheets(i).Name <> page Then
If ThisWorkbook.Worksheets(i).Visible = xlVeryHidden Or ThisWorkbook.Worksheets(i).Visible = False Then
ThisWorkbook.Worksheets(i).Visible = True
End If
End If
Next i
ActiveWorkbook.Protect Password:=pass
Application.EnableCancelKey = xlenabled
End Sub
Code to the closing of the file
Dim i As Integer
Dim pass, page As String
pass = "the password you've set for the workbook protection"
page = "the name of your warning page"
Application.EnableCancelKey = xlDisabled
ActiveWorkbook.Unprotect Password:=palavra_chave
For i = 1 To ThisWorkbook.Worksheets.Count
' Skip empty sheets And hidden sheets
If ThisWorkbook.Worksheets(i).Name <> page Then
If ThisWorkbook.Worksheets(i).Visible = True Then
ThisWorkbook.Worksheets(i).Visible = xlVeryHidden
End If
End If
Next i
ActiveWorkbook.Protect Password:=pass
Application.EnableCancelKey = xlenabled
End Sub
I've already included in the code written above two lines to disable the "cancel key" aka "ESC key" during the running of the macros to avoid people stoping the macro in the middle because during the macro the workbook gets temporarilly unprotected - the macro unprotects the workbook in the beginning in order to be able to change the properties of the sheets and then sets the password again at the end of the macro, that is why you have to disable the cancel option during the macro.
Hope this helps...
Just to tease you guys, this will not stop people from messing with your files.
I've been working on the code to prevent any change to the file and to only show the sheets I want and still haven't find the answer to solve all the little bugs... there are still ways to "crack" my protection...