Macro to Protect worksheets in Excel


Protect every worksheet in a workbook with a Password


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

Unprotect every protected worksheet in a workbook


Sub UnProtectEveryWorksheet()
Dim Pass As String
Dim Y As Worksheet
Pass = InputBox("Enter the Password to Unprotect the worksheets", "UnProtect worksheets")
If Pass = Sonder Then
For Each Y In ActiveWorkbook.Worksheets
Y.Unprotect Password:=Sonder
Next Y
Else
MsgBox "Incorrect Password"
End If
End Sub

How to use codes shared here?