Cells object question

R

Robert Crandal

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!
 
P

Peter T

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
 
D

Dave Peterson

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.
 
R

Robert Crandal

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top