• Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User

    Hui...

  • When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

Enable and Disable Password Protection

cyliyu

Member
I would like to have a macro buttons to enable and disable the worksheet protection.
and I would like the code to be flexible so that I can have some sheets protected, some not?

e.g. Sheet 1, Sheet 3, Sheet 5 etc.- protected
sheet 2, sheet 4, sheet 6 etc.- unprotected.

The code should prompt for password to protect and unprotect the sheets.

Thanks.
 
See attached.
In this example only Sheet 4 is protected/unprotected.
 

Attachments

  • (Un)protect sheets.xlsb
    19.5 KB · Views: 8
Thanks, Belleke for your reply.
Your sample will have Blad2, Blad3 and Blad4 protected/unprotected except the "start" sheet.
 
I have the protect and unprotect code as the attached file using Array.
It will protect and unprotect "Sheet1", "Sheet3" and "Sheet5". "Sheet7" was set with a password of a number of "7".
I need help with the following code. It supposes to display the Notification at the end of the unprotect execution but it doesn't work.

upload_2018-2-24_20-26-13.png
upload_2018-2-24_20-27-30.png
Can anyone help?

Code:
If Len(msg) > 0 Then
  MsgBox "The following worksheets are protected under a different password and were not unlocked" & _
  vbCrLf & msg, 64, "Notification"
  End If
 
  If Len(msg2) > 0 Then
  MsgBox "The following worksheets were unlocked" & _
  vbCrLf & msg2, 64, "Notification"
  End If
 

Attachments

  • (Un)Protect Sheets.xlsm
    28.5 KB · Views: 3
Back
Top