Sub ProtectAllSheetsWithOnePassword()
Dim ws As Worksheet
Dim pwd As String
pwd = InputBox("Enter the password to protect all sheets:", "Protect All Sheets")
If pwd = "" Then
MsgBox "No password entered. Protection cancelled."
Exit Sub
End If
For Each ws In ThisWorkbook.Worksheets
ws.Cells.Locked = True
ws.Protect Password:=pwd, _
DrawingObjects:=True, _
Contents:=True, _
Scenarios:=True, _
AllowFiltering:=True
Next ws
ThisWorkbook.Protect Password:=pwd, Structure:=True
MsgBox "All worksheet tabs and the workbook structure are now protected."
End Sub
That will protect every worksheet and also protect the workbook structure so users cannot easily add, delete, move, rename, or hide/unhide tabs.
Protect Sheet stops people from editing cells.
Protect Workbook protects the workbook structure, meaning tabs cannot be moved, deleted, renamed, hidden, or added.
For your purpose, you want both, and the macro above does both.
Use this companion macro:
Sub UnprotectAllSheetsWithOnePassword()
Dim ws As Worksheet
Dim pwd As String
pwd = InputBox("Enter the password to unprotect all sheets:", "Unprotect All Sheets")
If pwd = "" Then
MsgBox "No password entered. Unprotect cancelled."
Exit Sub
End If
For Each ws In ThisWorkbook.Worksheets
ws.Unprotect Password:=pwd
Next ws
ThisWorkbook.Unprotect Password:=pwd
MsgBox "All worksheet tabs and workbook structure are now unprotected."
End Sub
Sheet protection prevents normal editing, but it is not the same as full file encryption. If the workbook contains sensitive information, also use:
File → Info → Protect Workbook → Encrypt with Password