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

How to fill five years of quarters?
Type 1Q-2023 in a cell. Grab the fill handle and drag down or right. After 4Q-2023, Excel will jump to 1Q-2024. Dash can be any character.
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,215,019
Messages
6,122,707
Members
449,093
Latest member
Mnur

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