protect and unprotect all sheets by a command button

uttamsaxena

Board Regular
Joined
Apr 22, 2003
Messages
182
I have a workbook with 10 sheets, which all are protected by the password(Tools>Protection>protect) . Users only feed data and any change in sheet is to be done by me every month. For editing something in each sheet, I have to protect and unprotect all sheets one by one.How can this be done by a command button on sheet one, which should ask for the password and on correct password shall unprotect all the sheets. Similarly another button on sheet 1 should lock all the sheets on confirmation of a password.

However for unprotecting and protecting single sheet, the normal method (Tools>Protection>unprotect) should do.
 

Excel Facts

Format cells as time
Select range and press Ctrl+Shift+2 to format cells as time. (Shift 2 is the @ sign).
uttamsaxena said:
I have a workbook with 10 sheets, which all are protected by the password(Tools>Protection>protect) . Users only feed data and any change in sheet is to be done by me every month. For editing something in each sheet, I have to protect and unprotect all sheets one by one.How can this be done by a command button on sheet one, which should ask for the password and on correct password shall unprotect all the sheets. Similarly another button on sheet 1 should lock all the sheets on confirmation of a password.

However for unprotecting and protecting single sheet, the normal method (Tools>Protection>unprotect) should do.

Private Sub CommandButton1_Click()
Dim ws As Worksheet
dim Password as string
Password = Inputbox "Password"
For Each ws In ActiveWorkbook.Worksheets
If ws.ProtectContents = True Then
ws.Unprotect Password
Else
ws.Protect Password
End If
Next
End Sub
 
Upvote 0

Forum statistics

Threads
1,214,522
Messages
6,120,022
Members
448,939
Latest member
Leon Leenders

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top