Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 18
Default Using VBA to Unlock Cells

I have the following code when my workbook opens:
Public Sub Workbook_Open()
ThisWorkbook.Sheets(3).Range("L4").Value = NextSeqNumber
ThisWorkbook.Sheets(3).Range("data1").Value = Date
With Sheet3
'Unlock cells for data entry
[E12:E15, G14, I14, L13:L15, K14:K15, D18:K34, G37:G38, D37:D39,
E40:E41, F42].Locked = False
.Protect 'Protect worksheet
End With
End Sub

The sequential number and date do work because I had that code working
before adding the code to unlock the cells noted and protect the rest of the
worksheet from being changed.

When I open it, I get the following message:
Run time error 1004 Unable to set the Locked property of the Range class.

This is a template file if that would make any difference. There are some
named cell references in this worksheet but none of them are called "class".
I'm using Excel 2003 SP1 on Windows XP SP2.

Thanks for any insight.
Marcia
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,327
Default Using VBA to Unlock Cells

Hi Marcia

You'll need a
..Unprotect
before the unlocking if the sheet is protected.

HTH. Best wishes Harald



"Office User" skrev i melding
...
I have the following code when my workbook opens:
Public Sub Workbook_Open()
ThisWorkbook.Sheets(3).Range("L4").Value = NextSeqNumber
ThisWorkbook.Sheets(3).Range("data1").Value = Date
With Sheet3
'Unlock cells for data entry
[E12:E15, G14, I14, L13:L15, K14:K15, D18:K34, G37:G38,

D37:D39,
E40:E41, F42].Locked = False
.Protect 'Protect worksheet
End With
End Sub

The sequential number and date do work because I had that code working
before adding the code to unlock the cells noted and protect the rest of

the
worksheet from being changed.

When I open it, I get the following message:
Run time error 1004 Unable to set the Locked property of the Range class.

This is a template file if that would make any difference. There are some
named cell references in this worksheet but none of them are called

"class".
I'm using Excel 2003 SP1 on Windows XP SP2.

Thanks for any insight.
Marcia



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 114
Default Using VBA to Unlock Cells

Hi Marcia

If I'm applying .Protect to a WorkSheet, I like to use the
UserInterfaceOnly argument like so:

Sheet3.Protect, , , True or
Sheet3.Protect UserInterfaceOnly:=True

That way your worksheet is protected but any macros you write are not
affected by the protection (ie, you can change a value on a worksheet
while it is protected, which a user cannot do)

Regards

Paul Martin
Melbourne, Australia

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 18
Default Using VBA to Unlock Cells

I added the suggestions from Paul and Harald but still getting the same error
message: Run time error 1004 Unable to set the Locked property of the Range
class.

Here's the code now:
Public Sub Workbook_Open()
ThisWorkbook.Sheets(3).Range("L4").Value = NextSeqNumber
ThisWorkbook.Sheets(3).Range("data1").Value = Date
With Sheet3
.Unprotect
Cells.Locked = True
'Unlock cells for data entry
[E12:E15, G14, I14, L13:L15, K14:K15, D18:K34, G37:G38, D37:D39,
E40:E41, F42].Locked = False
.Protect UserInterfaceOnly:=True 'Protect worksheet
End With
End Sub

Thanks for any input.
Marcia

"Paul Martin" wrote:

Hi Marcia

If I'm applying .Protect to a WorkSheet, I like to use the
UserInterfaceOnly argument like so:

Sheet3.Protect, , , True or
Sheet3.Protect UserInterfaceOnly:=True

That way your worksheet is protected but any macros you write are not
affected by the protection (ie, you can change a value on a worksheet
while it is protected, which a user cannot do)

Regards

Paul Martin
Melbourne, Australia


  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Using VBA to Unlock Cells

the unqualified Cells pertains to the activesheet which many not be sheet3

Public Sub Workbook_Open()
ThisWorkbook.Sheets(3).Range("L4").Value = NextSeqNumber
ThisWorkbook.Sheets(3).Range("data1").Value = Date
With Sheet3
.Unprotect
.Cells.Locked = True
'Unlock cells for data entry
.[E12:E15, G14, I14, L13:L15, K14:K15, D18:K34, G37:G38,
D37:D39,
E40:E41, F42].Locked = False
.Protect UserInterfaceOnly:=True 'Protect worksheet
End With
End Sub

You need periods before Cells and [E12:E15, . . .

--
Regards,
Tom Ogilvy

"Office User" wrote in message
...
I added the suggestions from Paul and Harald but still getting the same

error
message: Run time error 1004 Unable to set the Locked property of the

Range
class.

Here's the code now:
Public Sub Workbook_Open()
ThisWorkbook.Sheets(3).Range("L4").Value = NextSeqNumber
ThisWorkbook.Sheets(3).Range("data1").Value = Date
With Sheet3
.Unprotect
Cells.Locked = True
'Unlock cells for data entry
[E12:E15, G14, I14, L13:L15, K14:K15, D18:K34, G37:G38,

D37:D39,
E40:E41, F42].Locked = False
.Protect UserInterfaceOnly:=True 'Protect worksheet
End With
End Sub

Thanks for any input.
Marcia

"Paul Martin" wrote:

Hi Marcia

If I'm applying .Protect to a WorkSheet, I like to use the
UserInterfaceOnly argument like so:

Sheet3.Protect, , , True or
Sheet3.Protect UserInterfaceOnly:=True

That way your worksheet is protected but any macros you write are not
affected by the protection (ie, you can change a value on a worksheet
while it is protected, which a user cannot do)

Regards

Paul Martin
Melbourne, Australia






  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 18
Default Using VBA to Unlock Cells

Thanks. That should have been obvious to me. Sometimes it's the little
things that will trip you up. :-(
Marcia

"Tom Ogilvy" wrote:

the unqualified Cells pertains to the activesheet which many not be sheet3

Public Sub Workbook_Open()
ThisWorkbook.Sheets(3).Range("L4").Value = NextSeqNumber
ThisWorkbook.Sheets(3).Range("data1").Value = Date
With Sheet3
.Unprotect
.Cells.Locked = True
'Unlock cells for data entry
.[E12:E15, G14, I14, L13:L15, K14:K15, D18:K34, G37:G38,
D37:D39,
E40:E41, F42].Locked = False
.Protect UserInterfaceOnly:=True 'Protect worksheet
End With
End Sub

You need periods before Cells and [E12:E15, . . .

--
Regards,
Tom Ogilvy

"Office User" wrote in message
...
I added the suggestions from Paul and Harald but still getting the same

error
message: Run time error 1004 Unable to set the Locked property of the

Range
class.

Here's the code now:
Public Sub Workbook_Open()
ThisWorkbook.Sheets(3).Range("L4").Value = NextSeqNumber
ThisWorkbook.Sheets(3).Range("data1").Value = Date
With Sheet3
.Unprotect
Cells.Locked = True
'Unlock cells for data entry
[E12:E15, G14, I14, L13:L15, K14:K15, D18:K34, G37:G38,

D37:D39,
E40:E41, F42].Locked = False
.Protect UserInterfaceOnly:=True 'Protect worksheet
End With
End Sub

Thanks for any input.
Marcia

"Paul Martin" wrote:

Hi Marcia

If I'm applying .Protect to a WorkSheet, I like to use the
UserInterfaceOnly argument like so:

Sheet3.Protect, , , True or
Sheet3.Protect UserInterfaceOnly:=True

That way your worksheet is protected but any macros you write are not
affected by the protection (ie, you can change a value on a worksheet
while it is protected, which a user cannot do)

Regards

Paul Martin
Melbourne, Australia





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
unlock frozen cells Windows 7 Excel Discussion (Misc queries) 2 April 30th 10 02:49 PM
How unlock locked cells Robin Excel Discussion (Misc queries) 2 August 24th 09 03:16 AM
Unlock cells Siva Excel Discussion (Misc queries) 1 April 26th 07 04:04 PM
how do i password protect an .xls file? how do i unlock it for automation. e.g. want to unlock and access a .xls from another .xls macro. Daniel Excel Worksheet Functions 1 June 24th 05 02:59 PM
Lock and Unlock Cells Peter Excel Programming 5 January 29th 05 04:32 PM


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