Function to detect if Sheet is protected

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
 
H

Harald Staff

Hi Niklas

One way:

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

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top