MS Excel

G

Garg Swadesh

Can we protact two or more sheets simultaneously using one password.
Similarly can we unprotect two or more sheets in single command having one
password.
 
M

macropod

Hi Garg Swadesh,

No, they have to be done one at a time, but you could use a macro to automate the processes, thus requiring the user to input the
password only once. For example, the following 'ProtectAllSheets' code protects all unprotected sheets, while the
'UnprotectAllSheets' code does the opposite:

Sub ProtectAllSheets()
Dim wkSheet As Worksheet
For Each wkSheet In ActiveWorkbook.Worksheets
If wkSheet.ProtectContents <> True Then
wkSheet.Protect Password:=InputBox("Please enter the password")
End If
Next wkSheet
End Sub

Sub UnprotectAllSheets()
Dim wkSheet As Worksheet
For Each wkSheet In ActiveWorkbook.Worksheets
If wkSheet.ProtectContents = True Then
wkSheet.Unprotect Password:=InputBox("Please enter the password")
End If
Next wkSheet
End Sub


Cheers
 
Top