MS Excel

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

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.
 
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top