View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.misc
OssieMac OssieMac is offline
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