Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default Locking cells, Excel 2003 SP3

Hi
I have Excel 2003 SP3 and I have what I thought was correct code when
investigating other peoples issues. However at the end of the loop, the whole
sheet is protected, not just the cells. How do I start from an unprotected
sheet, lock some cells only, and keep the remainder of the sheet protected?
(I have tried with unprotect and protect out of the loop
Thanks

'rstData is a dataset of info which has a column that has an Excel Cell
name such as C10, B23, F16
Set rstData = oDatabase.RecordsetData
With rstData
.MoveFirst
Do While Not .EOF
ActiveWorkbook.ActiveSheet.Unprotect Password:="MyPwd"
ActiveWorkbook.ActiveSheet.Range(rstData("ExcelCel lPos")).Locked
= True
ActiveWorkbook.ActiveSheet.Protect Password:="MyPwd"
.MoveNext
Loop
End With
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,565
Default Locking cells, Excel 2003 SP3

My understanding of it is that the sheet is first protected with all cells
locked. The specified cells must then be unlocked for modification of
content. The remainder of the sheet is still protected.


"thebison" wrote in message
...
Hi
I have Excel 2003 SP3 and I have what I thought was correct code when
investigating other peoples issues. However at the end of the loop, the
whole
sheet is protected, not just the cells. How do I start from an unprotected
sheet, lock some cells only, and keep the remainder of the sheet
protected?
(I have tried with unprotect and protect out of the loop
Thanks

'rstData is a dataset of info which has a column that has an Excel Cell
name such as C10, B23, F16
Set rstData = oDatabase.RecordsetData
With rstData
.MoveFirst
Do While Not .EOF
ActiveWorkbook.ActiveSheet.Unprotect Password:="MyPwd"

ActiveWorkbook.ActiveSheet.Range(rstData("ExcelCel lPos")).Locked
= True
ActiveWorkbook.ActiveSheet.Protect Password:="MyPwd"
.MoveNext
Loop
End With



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,049
Default Locking cells, Excel 2003 SP3

your logic needs to be reversed.

First you Unprotect the cells that you're ok with others changing.
Next you protect the sheet. only those unprotected cells can now be edited.

"thebison" wrote in message
...
Hi
I have Excel 2003 SP3 and I have what I thought was correct code when
investigating other peoples issues. However at the end of the loop, the
whole
sheet is protected, not just the cells. How do I start from an unprotected
sheet, lock some cells only, and keep the remainder of the sheet
protected?
(I have tried with unprotect and protect out of the loop
Thanks

'rstData is a dataset of info which has a column that has an Excel Cell
name such as C10, B23, F16
Set rstData = oDatabase.RecordsetData
With rstData
.MoveFirst
Do While Not .EOF
ActiveWorkbook.ActiveSheet.Unprotect Password:="MyPwd"

ActiveWorkbook.ActiveSheet.Range(rstData("ExcelCel lPos")).Locked
= True
ActiveWorkbook.ActiveSheet.Protect Password:="MyPwd"
.MoveNext
Loop
End With


  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default Locking cells, Excel 2003 SP3

Many thanks to you both, I only have a few cells to lock and a lot of cells
that are unlocked but okay, understand. Many thanks

"JLGWhiz" wrote:

My understanding of it is that the sheet is first protected with all cells
locked. The specified cells must then be unlocked for modification of
content. The remainder of the sheet is still protected.


"thebison" wrote in message
...
Hi
I have Excel 2003 SP3 and I have what I thought was correct code when
investigating other peoples issues. However at the end of the loop, the
whole
sheet is protected, not just the cells. How do I start from an unprotected
sheet, lock some cells only, and keep the remainder of the sheet
protected?
(I have tried with unprotect and protect out of the loop
Thanks

'rstData is a dataset of info which has a column that has an Excel Cell
name such as C10, B23, F16
Set rstData = oDatabase.RecordsetData
With rstData
.MoveFirst
Do While Not .EOF
ActiveWorkbook.ActiveSheet.Unprotect Password:="MyPwd"

ActiveWorkbook.ActiveSheet.Range(rstData("ExcelCel lPos")).Locked
= True
ActiveWorkbook.ActiveSheet.Protect Password:="MyPwd"
.MoveNext
Loop
End With




  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 9,101
Default Locking cells, Excel 2003 SP3

Try something like this

ActiveWorkbook.ActiveSheet.Unprotect Password:="MyPwd"
Set rstData = oDatabase.RecordsetData
for each MyRow in RstData.rows
MyRow.entireRow.Locked
next Myrow
ActiveWorkbook.ActiveSheet.Protect Password:="MyPwd"


"thebison" wrote:

Many thanks to you both, I only have a few cells to lock and a lot of cells
that are unlocked but okay, understand. Many thanks

"JLGWhiz" wrote:

My understanding of it is that the sheet is first protected with all cells
locked. The specified cells must then be unlocked for modification of
content. The remainder of the sheet is still protected.


"thebison" wrote in message
...
Hi
I have Excel 2003 SP3 and I have what I thought was correct code when
investigating other peoples issues. However at the end of the loop, the
whole
sheet is protected, not just the cells. How do I start from an unprotected
sheet, lock some cells only, and keep the remainder of the sheet
protected?
(I have tried with unprotect and protect out of the loop
Thanks

'rstData is a dataset of info which has a column that has an Excel Cell
name such as C10, B23, F16
Set rstData = oDatabase.RecordsetData
With rstData
.MoveFirst
Do While Not .EOF
ActiveWorkbook.ActiveSheet.Unprotect Password:="MyPwd"

ActiveWorkbook.ActiveSheet.Range(rstData("ExcelCel lPos")).Locked
= True
ActiveWorkbook.ActiveSheet.Protect Password:="MyPwd"
.MoveNext
Loop
End With




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
File Saving/Locking with Excel different between 2003 AND 2007 Phil Smith Excel Discussion (Misc queries) 0 May 24th 10 07:29 PM
Locking a cell after data entry (Excel 2003) jeffparker98 Excel Discussion (Misc queries) 0 September 19th 08 07:38 PM
locking excel 2003 custom column width Biilll Excel Worksheet Functions 0 January 2nd 08 03:39 PM
Conditional Locking of Cells-Excel 2003 MikeTVC Excel Worksheet Functions 1 November 16th 07 07:13 PM
locking formula in cells in without locking whole sheet SuziQ Excel Discussion (Misc queries) 1 July 21st 06 03:58 PM


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