Protect/unprotect ALL worksheets in workbook ?

G

Guest

-- Is it possible to protect/unprotect all worksheets in a workbook at once
instead of having to do each individually if the password is the same?

News Gal
 
C

Chip Pearson

The only way to do that is with some VBA code:

Sub ProtectAll()
Dim WS As Worksheet
For Each WS In ActiveWorkbook.Worksheets
WS.Protect Password:="whatever"
Next WS
End Sub


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com
 
R

Ron de Bruin

The only way is to use a macro to do this

Sub test()
Dim sh As Worksheet
For Each sh In ThisWorkbook.Worksheets
sh.Unprotect "ron"
Next sh
End Sub

Or
sh.Protect "ron"
 
G

Guest

This macro would do the trick

Sub Unprotect()

Dim wb As Workbook
Dim ws As Worksheet
Dim blnIsProtected As Boolean
Set wb = ActiveWorkbook

For Each ws In wb.Worksheets
ws.Unprotect "test"
Next ws

Set wb = Nothing
Set ws = Nothing

End Sub
 
E

ers18

I need to know how to protect the entire worksheet (all tabs within it) with
a click of a button; not sure what the last solution entails. Please help.

ers
 
G

Gord Dibben

Sub ProtectAllSheets()
Application.ScreenUpdating = False
Dim n As Single
For n = 1 To Sheets.Count
Sheets(n).Protect Password:="justme"
Next n
Application.ScreenUpdating = True
End Sub

Sub UnprotectAllSheets()
Application.ScreenUpdating = False
Dim n As Single
For n = 1 To Sheets.Count
Sheets(n).Unprotect Password:="justme"
Next n
Application.ScreenUpdating = True
End Sub


Gord Dibben MS Excel MVP
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top