📊 VBA (Excel)
Protect All Sheets
Applies sheet protection with a given password to every worksheet in the workbook.
ProtectAllSheets.bas
Attribute VB_Name = "ProtectAllSheets"
Option Explicit
Public Sub ProtectAllSheets()
Dim ws As Worksheet
Dim pwd As String
pwd = InputBox("Enter a password to protect all sheets:", "Protect All Sheets")
If pwd = "" Then
MsgBox "Cancelled — no password entered.", vbExclamation
Exit Sub
End If
For Each ws In ThisWorkbook.Worksheets
ws.Protect Password:=pwd
Next ws
MsgBox "All " & ThisWorkbook.Worksheets.Count & " sheet(s) protected.", vbInformation
End Sub