PC Review


Reply
Thread Tools Rate Thread

Cells object question

 
 
Robert Crandal
Guest
Posts: n/a
 
      23rd Feb 2010
I am using the Cells object to set the "locked" property of
my spreadsheet. The line looks like this:

Cells.locked = True ' or can be False

I feel real uncomfortable using that code by itself. Shouldn't
I pre-qualify the Cells object with another object such as
"ThisWorkbook" or something?? I just want to ensure that
this code runs on the workbook it was intended for and not
another active workbook.

Thank you!


 
Reply With Quote
 
 
 
 
Peter T
Guest
Posts: n/a
 
      23rd Feb 2010
Unless you know for certain that the sheet you are concerned with is the
activesheet then yes, you should always qualify the range object with the
relevant sheet, eg

ThisWorkbook.Worksheets("Sheet1").Cells.etc

In passing, I can't imagine why one would ever do .Cells.locked = False

Regards,
Peter T


"Robert Crandal" <(E-Mail Removed)> wrote in message
news:FMXgn.19721$(E-Mail Removed)...
>I am using the Cells object to set the "locked" property of
> my spreadsheet. The line looks like this:
>
> Cells.locked = True ' or can be False
>
> I feel real uncomfortable using that code by itself. Shouldn't
> I pre-qualify the Cells object with another object such as
> "ThisWorkbook" or something?? I just want to ensure that
> this code runs on the workbook it was intended for and not
> another active workbook.
>
> Thank you!
>
>



 
Reply With Quote
 
Dave Peterson
Guest
Posts: n/a
 
      23rd Feb 2010
I always try to qualify my ranges.

With activesheet
.cells.locked = ...

Actually, I'd use:

Dim wks as worksheet
set wks = activesheet

with wks
.cells.locked = ...

By using that wks variable (declared as a worksheet), I'll get all the helpful
intellisense from the VBE. I think it makes writing code much easier.

Robert Crandal wrote:
>
> I am using the Cells object to set the "locked" property of
> my spreadsheet. The line looks like this:
>
> Cells.locked = True ' or can be False
>
> I feel real uncomfortable using that code by itself. Shouldn't
> I pre-qualify the Cells object with another object such as
> "ThisWorkbook" or something?? I just want to ensure that
> this code runs on the workbook it was intended for and not
> another active workbook.
>
> Thank you!


--

Dave Peterson
 
Reply With Quote
 
Robert Crandal
Guest
Posts: n/a
 
      23rd Feb 2010
Maybe because not all sheets need to have protection??? For example, nobody
uses my personal PC, and I don't care whether or not some of my sheets
or protected or not.....therefore, all the cells may be unlocked with a
call to ".Cells.locked = False"??? But ya, I understand that most people
would
rather have their spreadsheet entirely locked.


"Peter T" <peter_t@discussions> wrote in message
news:(E-Mail Removed)...
>
> In passing, I can't imagine why one would ever do .Cells.locked = False
>


 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Excell named cells or labeled cells question farseer@optonline.net Microsoft Excel Programming 8 25th Jun 2006 05:15 PM
Excel named cells or labeled cells question farseer@optonline.net Microsoft Excel Programming 2 25th Jun 2006 04:39 PM
Question about a System.Threading.Timer object and the "state" object you pass to it... Paul Tomlinson Microsoft C# .NET 1 13th May 2005 01:11 PM
Memory question when returning an object from inside another object Steven Blair Microsoft C# .NET 10 11th Jan 2005 07:15 PM
Question: Object Reference not set to an instance of an object. =?Utf-8?B?TWFubnkgQ2hvaGFu?= Microsoft ASP .NET 4 3rd Jan 2005 09:54 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 02:03 AM.