View Single Post
  #5   Report Post  
Posted to microsoft.public.excel.programming
Andy Andy is offline
external usenet poster
 
Posts: 414
Default Prevent selecting locked cells

Thanks Tom, so the EnableSelection property is only persistent if the sheet
is protected manually rather than by code? I still don't understand why
there is a difference between doing it manually and through code. By using
VBA code shouldn't the end result be the same as clicking toolbar buttons and
dialogs?! I've even tried recording a macro as I do the changes manually and
the code it records is the same as I have written. I guess if this is
defintiely the case, my only option is to leave it to the user to manually
protect each worksheet once the rest of the code has run...


"Tom Ogilvy" wrote:

Just to add:
To the best of my knowledge, at least in xl97 and xl2000, the
enableselection setting is not persistent if set manually or with code. In
Excel 2002/3 there are options for this in the enhanced sheet protection
dialog. I don't have xl2003 installed, but I found the behavior you
describe in xl2002. If the sheet is protected manually and the choices made
in that dialog (either previously by code [retain the settings displayed] or
by hand [make a change or not]) and the workbook is saved, then the setting
is retained. If the sheet is not protected, then the settings are not
retained. Making a selection via code and protecting the workbook - the
settings are not retained. This refers to after closing and then
reopening the workbook.

--
Regards,
Tom Ogilvy

"Andy" wrote in message
...
I would like to be able to prevent users from selecting locked cells in a
worksheet and to do this have used the EnableSelection property with the
Protect method. The problem I had was that when the workbook is closed

and
re-opened the locked cells are still selectable. Having looked at

previous
posts I see that this is because the EnableSelection property is not
persistent. However, it does seem to be persistent if I manually protect

the
worksheet so that only unlocked cells can be selected. How come this can't

be
achieved with VBA?