Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 230
Default Mass Protect and unProtect

Is there some code that will protect and some more code that will Unprotect
all spreadsheets in a workbook?

I thought something like this would work if I named all the sheets, but it
doesn't!
Copied from Help and change Select to
Protect.........Worksheets(Array("Sheet1", "Sheet2", "Sheet4")).Protect
What's wrong with this code? ("Says subscript out of range") All those
sheets exist. In fact this won't even work on 1 sheet!

However, I'd rather some code that did all the sheets, even if I added
others.

Rob


  #2   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 2,510
Default Mass Protect and unProtect

Hi Rob,

The following works but depending on just what you want to protect, you
might want to set some more parameters for the protect.

Sub Test_Protect()

Dim ws As Worksheet

For Each ws In Worksheets
ws.Protect Password:="ossiemac"
Next ws

End Sub

Sub Test_Un_Protect()

Dim ws As Worksheet

For Each ws In Worksheets
ws.Unprotect Password:="ossiemac"
Next ws

End Sub


--
Regards,

OssieMac


"RobN" wrote:

Is there some code that will protect and some more code that will Unprotect
all spreadsheets in a workbook?

I thought something like this would work if I named all the sheets, but it
doesn't!
Copied from Help and change Select to
Protect.........Worksheets(Array("Sheet1", "Sheet2", "Sheet4")).Protect
What's wrong with this code? ("Says subscript out of range") All those
sheets exist. In fact this won't even work on 1 sheet!

However, I'd rather some code that did all the sheets, even if I added
others.

Rob



  #3   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 230
Default Mass Protect and unProtect

Thanks OssieMac, just what I needed!!!

Just a matter of interest, any idea why the UnProtect runs MUCH slower? The
sheets are mainly filled with charts, Pivot Tables and Pivot Charts & Data.
Not too many formulas. There are 23 sheets and takes 5 seconds to UnProtect
and about 1/2 sec to Protect.

Rob

"OssieMac" wrote in message
...
Hi Rob,

The following works but depending on just what you want to protect, you
might want to set some more parameters for the protect.

Sub Test_Protect()

Dim ws As Worksheet

For Each ws In Worksheets
ws.Protect Password:="ossiemac"
Next ws

End Sub

Sub Test_Un_Protect()

Dim ws As Worksheet

For Each ws In Worksheets
ws.Unprotect Password:="ossiemac"
Next ws

End Sub


--
Regards,

OssieMac


"RobN" wrote:

Is there some code that will protect and some more code that will
Unprotect
all spreadsheets in a workbook?

I thought something like this would work if I named all the sheets, but
it
doesn't!
Copied from Help and change Select to
Protect.........Worksheets(Array("Sheet1", "Sheet2", "Sheet4")).Protect
What's wrong with this code? ("Says subscript out of range") All those
sheets exist. In fact this won't even work on 1 sheet!

However, I'd rather some code that did all the sheets, even if I added
others.

Rob





  #4   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 2,510
Default Mass Protect and unProtect

Hi again Rob,

Other than being facetious and saying that one can run faster going forwards
rather than backwards, I really dont know the answer. I think that it would
be necessary to have access to the source code and find out what Excel and
the macros have to process behind the scenes to answer the question.

However, I am pleased that I was able to help you with the original question.


--
Regards,

OssieMac


"RobN" wrote:

Thanks OssieMac, just what I needed!!!

Just a matter of interest, any idea why the UnProtect runs MUCH slower? The
sheets are mainly filled with charts, Pivot Tables and Pivot Charts & Data.
Not too many formulas. There are 23 sheets and takes 5 seconds to UnProtect
and about 1/2 sec to Protect.

Rob

"OssieMac" wrote in message
...
Hi Rob,

The following works but depending on just what you want to protect, you
might want to set some more parameters for the protect.

Sub Test_Protect()

Dim ws As Worksheet

For Each ws In Worksheets
ws.Protect Password:="ossiemac"
Next ws

End Sub

Sub Test_Un_Protect()

Dim ws As Worksheet

For Each ws In Worksheets
ws.Unprotect Password:="ossiemac"
Next ws

End Sub


--
Regards,

OssieMac


"RobN" wrote:

Is there some code that will protect and some more code that will
Unprotect
all spreadsheets in a workbook?

I thought something like this would work if I named all the sheets, but
it
doesn't!
Copied from Help and change Select to
Protect.........Worksheets(Array("Sheet1", "Sheet2", "Sheet4")).Protect
What's wrong with this code? ("Says subscript out of range") All those
sheets exist. In fact this won't even work on 1 sheet!

However, I'd rather some code that did all the sheets, even if I added
others.

Rob






  #5   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 230
Default Mass Protect and unProtect

Hi OssieMac,

It was just an interesting observation I made, particularly as there is no
other code! I'm just running your code in a couple of modules as stand
alones.

Anyway, no need to reply, but thanks.

Rob
"OssieMac" wrote in message
...
Hi again Rob,

Other than being facetious and saying that one can run faster going
forwards
rather than backwards, I really don't know the answer. I think that it
would
be necessary to have access to the source code and find out what Excel and
the macros have to process behind the scenes to answer the question.

However, I am pleased that I was able to help you with the original
question.


--
Regards,

OssieMac


"RobN" wrote:

Thanks OssieMac, just what I needed!!!

Just a matter of interest, any idea why the UnProtect runs MUCH slower?
The
sheets are mainly filled with charts, Pivot Tables and Pivot Charts &
Data.
Not too many formulas. There are 23 sheets and takes 5 seconds to
UnProtect
and about 1/2 sec to Protect.

Rob

"OssieMac" wrote in message
...
Hi Rob,

The following works but depending on just what you want to protect, you
might want to set some more parameters for the protect.

Sub Test_Protect()

Dim ws As Worksheet

For Each ws In Worksheets
ws.Protect Password:="ossiemac"
Next ws

End Sub

Sub Test_Un_Protect()

Dim ws As Worksheet

For Each ws In Worksheets
ws.Unprotect Password:="ossiemac"
Next ws

End Sub


--
Regards,

OssieMac


"RobN" wrote:

Is there some code that will protect and some more code that will
Unprotect
all spreadsheets in a workbook?

I thought something like this would work if I named all the sheets,
but
it
doesn't!
Copied from Help and change Select to
Protect.........Worksheets(Array("Sheet1", "Sheet2",
"Sheet4")).Protect
What's wrong with this code? ("Says subscript out of range") All those
sheets exist. In fact this won't even work on 1 sheet!

However, I'd rather some code that did all the sheets, even if I added
others.

Rob








Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Protect/ unprotect worksheet cc Excel Discussion (Misc queries) 0 October 19th 07 09:27 PM
Protect-Unprotect all the sheets Gary Excel Worksheet Functions 7 February 26th 07 08:13 PM
Protect/Unprotect Worksheet djn Excel Discussion (Misc queries) 1 May 12th 05 11:27 PM
Is there any way that you can protect or unprotect a group of wor. CheriT63 Excel Discussion (Misc queries) 9 January 8th 05 08:40 PM
Protect/unprotect all worksheets Janna Excel Worksheet Functions 2 January 7th 05 01:01 AM


All times are GMT +1. The time now is 01:36 PM.

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

About Us

"It's about Microsoft Excel"