Excel VBA - Detect Sheet Protection Status

Is there code I can use (maybe in an if statement) that checks the current protection status of a sheet?

For example, if I use 2 toggle buttons to protect or unprotect a sheet BUT there are other piece of code in other modules that also protect and unprotect the sheet then I need those toggle buttons to react to the current status versus only when the user presses those.  The problem now is the toggle buttons may look like the sheet is protected when it really isn't.
rmc71291Asked:
Who is Participating?
 
Saqib Husain, SyedEngineerCommented:
You can try the
.protectcontents
property. For more discussions on this you can see

http://www.mrexcel.com/forum/excel-questions/87568-how-check-if-sheet-protected.html
0
 
rmc71291Author Commented:
Thanks.
0
 
Roy CoxGroup Finance ManagerCommented:
If you don't want the bother of checking then you can use ProtectWithUserInterFaceOnly to allow macros to make changes on protected sheets. See

http://excel-it.com/excel_userinterfaceonly.html

What you asked for could be

If ActiveSheet.ProtectContents Then
            msgbox ActiveSheet.Name & " is protected"
        Else
             msgbox ActiveSheet.Name & " is not protected"
        End If

Open in new window

0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.