Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6
Default Running a macro to protect a workbook on a already protected workbook UNprotects the workbook ??

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

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,302
Default Running a macro to protect a workbook on a already protected workbook UNprotects the workbook ??

Hi Wim,

The syntax for the Protect method includes a Password argument and, as it
relates to the workbook object includes two additional arguments: Structure
and Windows. All of the arguments are optional. The default values for the
Structure and Windows arguments is False. In consequence, your instruction:

ActiveWorkbook.Protect Password:=Range("adminpassword").Value


is an instuction to Excel not to protect either Windows or Structure. As
there is nothing left to protect, Excel treats your instruction as an
unprotect request.

Try manually protecting the workbbook with both the Windows and structure
options unchecked and, even with a password, the OK confirmation button
becomes unavailable.

---
Regards,
Norman



"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



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,123
Default Running a macro to protect a workbook on a already protected workbook UNprotects the workbook ??

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



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,302
Default Running a macro to protect a workbook on a already protected workbook UNprotects the workbook ??

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





  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,123
Default Running a macro to protect a workbook on a already protected workbook UNprotects the workbook ??

Hi Norman

I must go now but will look at it later.

--
Regards Ron de Bruin
http://www.rondebruin.nl


"Norman Jones" wrote in message ...
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









  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,123
Default Running a macro to protect a workbook on a already protected workbook UNprotects the workbook ??

I see it is solved now


--
Regards Ron de Bruin
http://www.rondebruin.nl


"Ron de Bruin" wrote in message ...
Hi Norman

I must go now but will look at it later.

--
Regards Ron de Bruin
http://www.rondebruin.nl


"Norman Jones" wrote in message ...
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









  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6
Default Running a macro to protect a workbook on a already protected workbook UNprotects the workbook ??

Thanks Guys for your help
It is all fixed now.

  #8   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default Running a macro to protect a workbook on a already protectedworkbook UNprotects the workbook ??

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
  #9   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,302
Default Running a macro to protect a workbook on a already protected workbook UNprotects the workbook ??

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



  #10   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default 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


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
Running Macros in a protected workbook Christian Excel Discussion (Misc queries) 1 July 19th 09 01:37 PM
Help:Running a macro in one excel workbook from another workbook R Kapoor Setting up and Configuration of Excel 3 January 13th 06 05:11 AM
Multiple workbook user's with Master workbook - all password protected Yvon Excel Discussion (Misc queries) 2 March 30th 05 01:34 PM
Running Macros in protected workbook petunia Excel Worksheet Functions 3 January 18th 05 09:24 PM
Open a password protected excel workbook from second workbook to fetch data using dynamic connection kaustav choudhury Excel Programming 2 April 3rd 04 06:18 AM


All times are GMT +1. The time now is 05:45 PM.

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

About Us

"It's about Microsoft Excel"