Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7
Default Macro for worksheet protection

Hi,

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

Thank you.
Floss
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 618
Default Macro for worksheet protection

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



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 52
Default Macro for worksheet protection

Hi Floos
How abour a custom function?
Public Function unprotectSh(Sh As String)
z = "YourPassword"
unprotectSh = Sheets(Sh).Unprotect(z)
End Function

Public Function protectSh(Sh As String)
z = "YourPassword"
protectSh = Sheets(Sh).Protect(z)
End Function

And use functions in your module, ie:
Sub Macro1()
unprotectSh("Sheet1")
'Do some stuff...
protectSh("Sheet1")
End Sub

HTH
Cordially
Pascal

"Floss" a écrit dans le message de
...
Hi,

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

to 'Unprotect' it.

Thank you.
Floss



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 313
Default Macro for worksheet protection

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




  #5   Report Post  
Posted to microsoft.public.excel.programming
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






  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 313
Default Macro for worksheet protection

Thank you BeeJay,

with a little modification now it realy works. Here is how it looks:

Sub Workbook_protectiona()

Dim ws As Worksheet
Application.ScreenUpdating = False
For Each ws In ActiveWorkbook.Worksheets
If Sheets("Entry").CheckBoxes("cbProtectSheet").Value = xlOn Then
ws.Protect DrawingObjects:=True, Contents:=True
Else
ws.Unprotect
End If
Next

End Sub

Tony

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

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



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
Excel Data Protection- AKA: Sheet/Macro Password Protection Mushman(Woof!) Setting up and Configuration of Excel 0 December 29th 09 06:50 AM
use a macro to automate excel worksheet password protection Bodyshopman Excel Discussion (Misc queries) 2 July 25th 07 01:21 AM
Cell Protection vs. Worksheet Protection kmwhitt Excel Discussion (Misc queries) 4 September 24th 06 02:37 AM
Worksheet protection is gone and only wokbook protection can be se Eric C. Excel Discussion (Misc queries) 4 May 2nd 06 04:50 PM
protection of worksheet lbuck Excel Discussion (Misc queries) 0 January 12th 06 06:59 PM


All times are GMT +1. The time now is 04:01 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"