
Use a user-defined function to check whether a
worksheet is protected
The function described here checks whether a worksheet is pro-
tected. First, you need to create a worksheet and protect it, then
write a user-defined function to test it.
4
To check whether a worksheet is protected:
1. Press <Alt+F11> to open the Visual Basic Editor.
2. From the Insert menu, click Module.
3. Type the following function:
Function ShProt(s As String) As Boolean
On Error GoTo errorM
If Sheets(s).ProtectContents = True Then
ShProt = True
End If
Exit Function
errorM:
ShProt = False
End Function
4. Close the VBA Editor by pressing <Alt+Q>.
5. Select any cell in the worksheet and type ...