Macro to Protect Worksheets in Excel


Protect Every Worksheet in a Workbook with a password


Sub ProtectEveryWorksheet()
Sonder = InputBox("Enter the Password to protect the worksheets", "Protect worksheets")
For Each XLnCAD In ActiveWorkbook.Worksheets
XLnCAD.Protect Password:=Sonder
Next XLnCAD
End Sub

Unprotect Every protected Worksheet in a Workbook


Sub UnProtectEveryWorksheet()
Dim Pass As String
Pass = InputBox("Enter the Password to Unprotect the worksheets", "UnProtect worksheets")
If Pass = Sonder Then
For Each XLnCAD In ActiveWorkbook.Worksheets
XLnCAD.Unprotect Password:=Sonder
'this password should be the same which you used to protect the sheets
Next XLnCAD
Else
MsgBox "Incorrect Password"
End If
End Sub

Leave a Reply

Your email address will not be published.Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.