Function to detect if Sheet is protected

  • Thread starter Thread starter Niklas
  • Start date Start date
N

Niklas

Hi
What is the best way to find out if a Sheet is protected?
Is this a good way?
Public Function IsSheetProtected(i_wsSheet As Worksheet)
As Boolean

On Error Resume Next
'A dummy password to test if sheet is
protected...assume that no one have this password.
i_wsSheet.Unprotect
("NoOneIsAllowedToHaveThisPassword")
If (Err.Number <> 0) Then
IsSheetProtected = True
Else
IsSheetProtected = False
End If

End Function

Regards
/Niklas
 
Hi Niklas

One way:

Function IsLocked(wks As Worksheet) As Boolean
IsLocked = wks.ProtectContents
End Function
 
Back
Top