ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Locked/Protect in Workbook_open not working in X2002 (https://www.excelbanter.com/excel-programming/271736-locked-protect-workbook_open-not-working-x2002.html)

Lydia[_2_]

Locked/Protect in Workbook_open not working in X2002
 
I created and used the following code in Excel 2000 with
no problems:

Private Sub Workbook_Open()

If Worksheets("BudgetForm").Protect = False Then
Worksheets("BudgetForm").Range("g16:g19").Locked = False
Worksheets("BudgetForm").Range("h16:h19").Locked = False
Worksheets("BudgetForm").Range("h25:h29").Locked = False
Worksheets("BudgetForm").Range("g31:g47").Locked = False
Worksheets("BudgetForm").Protect Contents:=True,
Objects:=True, Scenarios:=True
End If
ActiveWorkbook.Protect Structu=True, Windows:=False
Range("A1").Select
End Sub

But since I have upgraded to Excel 2002, I get an error
message when opening the workbook. The highlighted code is
the second line.

Any help is appreciated!

Rob Bovey

Locked/Protect in Workbook_open not working in X2002
 
Hi Lydia,

The fact that this code worked in Excel 2000 was a bug. The Protect
method of the Worksheet object can't be used to determine whether a
worksheet is protected or not. There are specific properties to query for
each type of worksheet protection applied, for example:

If Worksheets("BudgetForm").ProtectContents = False Then

End If

--
Rob Bovey, MCSE, MCSD, Excel MVP
Application Professionals
http://www.appspro.com/

* Please post all replies to this newsgroup *
* I delete all unsolicited e-mail responses *


"Lydia" wrote in message
...
I created and used the following code in Excel 2000 with
no problems:

Private Sub Workbook_Open()

If Worksheets("BudgetForm").Protect = False Then
Worksheets("BudgetForm").Range("g16:g19").Locked = False
Worksheets("BudgetForm").Range("h16:h19").Locked = False
Worksheets("BudgetForm").Range("h25:h29").Locked = False
Worksheets("BudgetForm").Range("g31:g47").Locked = False
Worksheets("BudgetForm").Protect Contents:=True,
Objects:=True, Scenarios:=True
End If
ActiveWorkbook.Protect Structu=True, Windows:=False
Range("A1").Select
End Sub

But since I have upgraded to Excel 2002, I get an error
message when opening the workbook. The highlighted code is
the second line.

Any help is appreciated!





All times are GMT +1. The time now is 08:49 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com