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

Whats the difference between CONCAT and CONCATENATE?
The newer CONCAT function can reference a range of cells. =CONCATENATE(A1,A2,A3,A4,A5) becomes =CONCAT(A1:A5)

Cbrine

Well-known Member
Joined
Dec 2, 2003
Messages
3,196
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
 
Master Excel Bundle

Excel contains over 450 functions, with more added every year. That’s a huge number, so where should you start? Right here with this bundle.

Forum statistics

Threads
1,152,820
Messages
5,772,462
Members
425,760
Latest member
paphon

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
Top