A Microsoft Office (Excel, Word) forum. OfficeFrustration

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

Go Back   Home » OfficeFrustration forum » Microsoft Excel » Worksheet Functions
Site Map Home Register Authors List Search Today's Posts Mark Forums Read  

protect / unprotect multiple sheets



 
 
Thread Tools Display Modes
  #1  
Old January 31st, 2004, 12:36 AM
Lisa Williams
external usenet poster
 
Posts: n/a
Default protect / unprotect multiple sheets

Hi, I'm trying to protect and of course, unprotect multiple sheets at the same time, without using the Tools/Protection/Protect Workbook option - that option is not protecting the way I want. I have many sheets in my file and would like to be able to select a range of them (I do know how to do that) and then do Tools/Protection/Protect Sheet and have the whole range of selected sheets be protected with the same password that I enter only once. Does anyone know how to do this? I'd really appreciate it if you can help. Thanks.
  #2  
Old January 31st, 2004, 01:13 AM
Gord Dibben
external usenet poster
 
Posts: n/a
Default protect / unprotect multiple sheets

Lisa

Cannot be done by grouping sheets. VBA required. The code below will
protect/unprotect all sheets. To protect/unprotect just certain sheet use the
code below the ***************** line.

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

************************************************** ********

Sub Protect_SomeSheets()
Dim sht As Worksheet
For Each sht In Sheets(Array("Sheet1", "Sheet2", "Sheet9", "Sheet11"))
sht.Protect Password:="justme"
Next sht
End Sub

Sub UnProtect_SomeSheets()
Dim sht As Worksheet
For Each sht In Sheets(Array("Sheet1", "Sheet2", "Sheet9", "Sheet11"))
sht.UnProtect Password:="justme"
Next sht
End Sub

You will have to edit the Sheets(Array names to suit.

Gord Dibben Excel MVP


On Fri, 30 Jan 2004 16:36:09 -0800, "Lisa Williams"
wrote:

Hi, I'm trying to protect and of course, unprotect multiple sheets at the same time, without using the Tools/Protection/Protect Workbook option - that option is not protecting the way I want. I have many sheets in my file and would like to be able to select a range of them (I do know how to do that) and then do Tools/Protection/Protect Sheet and have the whole range of selected sheets be protected with the same password that I enter only once. Does anyone know how to do this? I'd really appreciate it if you can help. Thanks.


  #3  
Old January 31st, 2004, 05:25 AM
Norman Harker
external usenet poster
 
Posts: n/a
Default protect / unprotect multiple sheets

Hi Lisa!

And to complete Gord's collection we have:

Public Sub ToggleProtect1()
' From J E McGimpsey. Modified by NH
Application.ScreenUpdating = False
Const PWORD As String = "not4u2see"
Dim wkSht As Worksheet
Dim statStr As String

For Each wkSht In ActiveWorkbook.Worksheets
With wkSht
statStr = statStr & vbNewLine & "Sheet " & .Name
If .ProtectContents Then
wkSht.Unprotect Password:=PWORD
statStr = statStr & ": Unprotected"
Else
wkSht.Protect Password:=PWORD
statStr = statStr & ": Protected"
End If
End With
Next wkSht
Application.ScreenUpdating = True
MsgBox Mid(statStr, 2)
End Sub

--
Regards
Norman Harker MVP (Excel)
Sydney, Australia

Excel and Word Function Lists (Classifications, Syntax and Arguments)
available free to good homes.


  #4  
Old January 31st, 2004, 06:31 PM
Lisa Williams
external usenet poster
 
Posts: n/a
Default protect / unprotect multiple sheets

Thanks - I appreciate it
 




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump


All times are GMT +1. The time now is 12:12 AM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 OfficeFrustration.
The comments are property of their posters.