How to protect / unprotect all sheets in one go using VBA in Excel

Опубликовано: 07 Август 2026
на канале: Learn In 5 Minutes
1,271
4

In this tutorial you will learn how protect and unprotect all worksheets in one go using VBA macro programming in Microsoft Excel

VBA Code:

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

'This code will unprotect all the sheets at one go
Sub UnprotectAllSheets()
Dim ws As Worksheet
Dim password As String
password = "Pass123" 'replace Test123 with the password you want
For Each ws In Worksheets
ws.Unprotect password:=password
Next ws
End Sub