Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 441
Default Lock cell selection cancels UserInterFaceOnly

I am using Office 2003 on Windows XP.

I use the following code which allows me to make programmatic changes to a
sheet even though protection is on:

Sheet1.Protect Password:="***", UserInterfaceOnly:=True

I also want to prevent the user from selecting locked cells, so I added the
following line to my function:

Sheet1.EnableSelection = xlUnlockedCells

But now, I can't make programmatic changes to the sheet without turning
protection off. My code fails on:

dValue = Sheet1.Range("M5").Formular1c1

It seems if I prevent the user from selecting "M5" this shouldn't stop my
code from getting this info, but it does. Why? How can I work around this?

Thanks much for your assistance.


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default Lock cell selection cancels UserInterFaceOnly

This line:

dValue = Sheet1.Range("M5").Formular1c1

isn't changing the sheet. It's grabbing the formula (in R1C1 notation) from a
cell.

Maybe you declared dValue incorrectly (depending on what was in that cell???).

Dim dValue As String
Sheet1.EnableSelection = xlUnlockedCells
Sheet1.Protect Password:="***", UserInterfaceOnly:=True
dValue = Sheet1.Range("M5").FormulaR1C1

But this worked ok for me, too:

Option Explicit
Sub testme()
Dim dValue As String
dValue = "=r1c1"
Sheet1.EnableSelection = xlUnlockedCells
Sheet1.Protect Password:="***", UserInterfaceOnly:=True
Sheet1.Range("M5").FormulaR1C1 = dValue
End Sub

quartz wrote:

I am using Office 2003 on Windows XP.

I use the following code which allows me to make programmatic changes to a
sheet even though protection is on:

Sheet1.Protect Password:="***", UserInterfaceOnly:=True

I also want to prevent the user from selecting locked cells, so I added the
following line to my function:

Sheet1.EnableSelection = xlUnlockedCells

But now, I can't make programmatic changes to the sheet without turning
protection off. My code fails on:

dValue = Sheet1.Range("M5").Formular1c1

It seems if I prevent the user from selecting "M5" this shouldn't stop my
code from getting this info, but it does. Why? How can I work around this?

Thanks much for your assistance.


--

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
I am using a macro and it cancels my formula Nelly Excel Worksheet Functions 3 September 6th 09 05:40 PM
How do you lock a cell after making a selection from a dropdown b GuyHUf Excel Worksheet Functions 0 June 25th 07 04:06 PM
I have lock a wookbook but one cell does not want to lock it Mimi Excel Discussion (Misc queries) 2 January 21st 07 10:59 PM
Lock data in a cell a specific cell based on selection on other ce CrimsonPlague29 Excel Worksheet Functions 0 May 10th 06 11:06 AM
Code cancels protection properties gavmer[_68_] Excel Programming 3 September 8th 04 07:47 AM


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