Posted to microsoft.public.excel.programming
|
|
Running a macro to protect a workbook on a already protectedworkbook UNprotects the workbook ??
Yep. It sure looks like if you're explicit with the options, then it isn't a
toggle anymore.
(At least when I tested in xl2003 <bg.)
Norman Jones wrote:
Hi Dave,
Why check at all?
The explicit assignment of argument values works for me:
Sub Workbook_Open()
ActiveWorkbook.Protect _
Password:=Sheets("Sheet1"). _
Range("Test").Value, _
Structu=True
End Sub
Or:
Sub Workbook_Open()
ActiveWorkbook.Protect _
Password:=Sheets("Sheet1"). _
Range("Test").Value, _
Structu=True, _
Windows:=True
End Sub
---
Regards,
Norman
"Dave Peterson" wrote in message
...
You could check both:
Option Explicit
Private Sub Workbook_Open()
With ActiveWorkbook
If .ProtectStructure = False _
And .ProtectWindows = False Then
.Protect _
Password:=Me.Worksheets("sheet1").Range("adminpass word").Value
End If
End With
End Sub
But I like this equivalent better--I just find it easier to
read/understand.
Option Explicit
Private Sub Workbook_Open()
With ActiveWorkbook
If .ProtectStructure = True _
Or .ProtectWindows = True Then
'do nothing
Else
.Protect _
Password:=Me.Worksheets("sheet1").Range("adminpass word").Value
End If
End With
End Sub
But either way, I would fully qualify the adminpassword range.
Norman Jones wrote:
Hi Ron,
If the original protection is applied progromatically, your suggestion
works
well for me.
If, however, I protect the workbook manually, selecting the Windows
option
only. then running your macro returned the workbook to its unprotected
state.
---
Regards,
Norman
"Ron de Bruin" wrote in message
...
Hi
Same problem in 2002
You can try this
Private Sub Workbook_Open()
If ActiveWorkbook.ProtectStructure = False Then
ActiveWorkbook.Protect Password:=Range("adminpassword").Value
End If
End Sub
--
Regards Ron de Bruin
http://www.rondebruin.nl
"WimR" wrote in message
oups.com...
My code in the workook_open() macro includes the following to ensure
the workbook is protected at all times.
ActiveWorkbook.Protect Password:=Range("adminpassword").Value
When this code runs while the workbook IS protected, it actually
causes
the workbook to be UNPROTECTED.
How strange is this ??!!
Does anybody know why this happens and how I can prevent this from
happening.
I am running Excel 2003
thank you very much for your help.
Wim
--
Dave Peterson
--
Dave Peterson
|