View Single Post
  #5   Report Post  
Posted to microsoft.public.excel.programming
BEEJAY BEEJAY is offline
external usenet poster
 
Posts: 247
Default Macro for worksheet protection

Tony:
Unless you really need a check box to select/deselect which sheets to
protect/unprotect, you may want to try the following - Each protects or
unprotects all worksheets, as well as the workbook itself.
I attached each one to an icon on a special tool bar, for easy
accesss/operation.
Hope this helps.
(the following is from this user group, Not MY brainchild)

BeeJay

Sub DraftProtectionOff()

Dim ws As Worksheet
Application.ScreenUpdating = False
For Each ws In ActiveWorkbook.Worksheets
If ws.ProtectContents = True Then
ws.Unprotect ("WSPassword")
End If
Next
ActiveWorkbook.Unprotect (["WBPassword"])
Application.ScreenUpdating = True
End Sub

Sub DraftProtectionOn()

Dim ws As Worksheet
Application.ScreenUpdating = False
For Each ws In ActiveWorkbook.Worksheets
If ws.ProtectContents = False Then
ws.Protect ("WSPassword")
End If
Next
ActiveWorkbook.Protect (["WBPassword"])
Application.ScreenUpdating = True

End Sub


"Tony" wrote:

Hi,

what have I to do to protect all sheets in my workbook by checkbox?
Tony


€žJulieD" napÃ*sal (napÃ*sala):

Hi Floss

ActiveSheet.Unprotect Password:="me"
ActiveSheet.Protect Password:="me"

this unprotects / protects the activesheet
when you want to specify the name of the sheet you can use

ThisWorkbook.Worksheets("Sheet1).Unprotect("YourPa ssword")
ThisWorkbook.Worksheets("Sheet1).Protect("YourPass word")

Cheers
julieD


"Floss" wrote in message
...
Hi,

Need help with macro code to run a passworded worksheet 'Protect' and one

to 'Unprotect' it.

Thank you.
Floss