ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Help with locking Cells (https://www.excelbanter.com/excel-programming/284626-help-locking-cells.html)

rthomsen

Help with locking Cells
 

Hi

I am trying to lock and unlock cells in an Excel 97 App via VB code. I
have the following function

Private Sub Workbook_Open()

ActiveSheet.Unprotect password:=Worksheets("sheet2").Range("PWD")

Worksheets("sheet1").Range("A1:BH22").Locked = True
Range("CompletedBy").Locked = False

ActiveSheet.Protect password:=Worksheets("Sheet2").Range("PWD"),
userinterfaceonly:=True
End Sub

Setting the Locked property works fine using a reference like "A1:B
H22" but fails when using a named range.

Does anyone have any idea why I cannot use a named range in this code.


------------------------------------------------
~~ Message posted from http://www.ExcelTip.com/
~~View and post usenet messages directly from http://www.ExcelForum.com/

~~Now Available: Financial Statements.xls, a step by step guide to creating financial statements

RADO[_3_]

Help with locking Cells
 
It seems to me it should work fine... are you sure you spelled the name of
the range correctly? are you sure that the name exists and has a valid
reference?

RADO


"rthomsen" wrote in message
...

Hi

I am trying to lock and unlock cells in an Excel 97 App via VB code. I
have the following function

Private Sub Workbook_Open()

ActiveSheet.Unprotect password:=Worksheets("sheet2").Range("PWD")

Worksheets("sheet1").Range("A1:BH22").Locked = True
Range("CompletedBy").Locked = False

ActiveSheet.Protect password:=Worksheets("Sheet2").Range("PWD"),
userinterfaceonly:=True
End Sub

Setting the Locked property works fine using a reference like "A1:B
H22" but fails when using a named range.

Does anyone have any idea why I cannot use a named range in this code.


------------------------------------------------
~~ Message posted from http://www.ExcelTip.com/
~~View and post usenet messages directly from http://www.ExcelForum.com/

~~Now Available: Financial Statements.xls, a step by step guide to

creating financial statements



JON JON

Help with locking Cells
 
Range(ActiveWorkbook.Names("CompletedBy")).Locked = False

"rthomsen" wrote in message
...

Hi

I am trying to lock and unlock cells in an Excel 97 App via VB code. I
have the following function

Private Sub Workbook_Open()

ActiveSheet.Unprotect password:=Worksheets("sheet2").Range("PWD")

Worksheets("sheet1").Range("A1:BH22").Locked = True
Range("CompletedBy").Locked = False

ActiveSheet.Protect password:=Worksheets("Sheet2").Range("PWD"),
userinterfaceonly:=True
End Sub

Setting the Locked property works fine using a reference like "A1:B
H22" but fails when using a named range.

Does anyone have any idea why I cannot use a named range in this code.


------------------------------------------------
~~ Message posted from http://www.ExcelTip.com/
~~View and post usenet messages directly from http://www.ExcelForum.com/

~~Now Available: Financial Statements.xls, a step by step guide to

creating financial statements




All times are GMT +1. The time now is 06:59 PM.

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