Unprotect All Worksheets with VBA

Looking for help on a spreadsheet? Perhaps you want to discuss a certain part of VBA code? Discuss all things Excel here!
Post Reply
User avatar
newsnatter
Site Admin
Posts: 15
Joined: Fri Jul 24, 2020 10:53 pm
Location: UK
Contact:

Are you dealing with a worksheet which has sheets protected? Do you need them unprotected to perform some tasks?

To unprotect all sheets in one go, simply add this to your VBA code:

Code: Select all

'This code will protect all the sheets at one go
Sub UnProtectAllSheets()
Dim ws As Worksheet
Dim password As String
password = "NN123" 'replace NN123 with the password you want
For Each ws In Worksheets
ws.Unprotect password:=password
Next ws
End Sub
Once finished, if you'd like to protect your sheets again, you can simply alter the code above to protect rather than unprotect like this:

Code: Select all

'This code will protect all the sheets at one go
Sub ProtectAllSheets()
Dim ws As Worksheet
Dim password As String
password = "NN123" 'replace NN123 with the password you want
For Each ws In Worksheets
ws.Protect password:=password
Next ws
End Sub
Post Reply