Cells object question

  • Thread starter Thread starter Robert Crandal
  • Start date Start date
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!
 
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
 
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.
 
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.
 
Back
Top