![]() |
![]() |
|
|||||||
| Excel Questions All Excel/VBA questions - formulas, macros, pivot tables, general help, etc. Please post to this forum in English only. |
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
New Member
Join Date: Mar 2002
Posts: 2
|
Can you write a macro to protect all sheets? I have many workbooks that have many sheets. They are veiwed by many people. I have to revise them frequently. The normal Tools, Protection, etc. on every sheet is a pain.
|
|
|
|
|
|
#2 |
|
MrExcel MVP
Join Date: Feb 2002
Location: Sunny, spring-like Hull
Posts: 3,339
|
Following should work OK, change the password to suit :-
Public Sub ProtectAll() Dim ws As Worksheet For Each ws In ActiveWorkbook.Worksheets ws.Protect password:="MyPass", DrawingObjects:=True, Contents:=True, Scenarios:=True Next ws End Sub |
|
|
|
|
|
#3 |
|
New Member
Join Date: Mar 2002
Posts: 2
|
Thanks, It works fine.
|
|
|
|
|
|
#4 |
|
Board Regular
Join Date: Mar 2002
Location: Near the Land of Oz
Posts: 1,550
|
I have many password protected workbooks/sheets. This is a great help. Thanks.
Now, can the reverse be done? Unprotecting all sheets at one time? |
|
|
|
|
|
#5 |
|
MrExcel MVP
Join Date: Feb 2002
Location: Sunny, spring-like Hull
Posts: 3,339
|
(Sort of) the reverse: -
Public Sub DeProtectAll() Dim ws As Worksheet For Each ws In ActiveWorkbook.Worksheets ws.Unprotect password:="MyPass" Next ws End Sub |
|
|
|
|
|
#6 |
|
Board Regular
Join Date: Mar 2002
Location: Near the Land of Oz
Posts: 1,550
|
Thanks. This will save me many, many keystrokes!!
__________________
- old, slow, and confused ... but at least I'm inconsistent - (retired Excel 2003 user, 3.28.2008)
|
|
|
|
![]() |
| Bookmarks |
| Thread Tools | |
| Display Modes | |
|
|