Protect worksheet - do not allow select cells

J

Jon

I want to protect a worksheet in a workbook that is not the one my code
is running from. I am able to do this with
Workbooks(FileName.xls).Sheets("Sheet1").Protect Password:="password"

The problem is that by default Excel allows the cells of a protected
sheet. to be selected. I do not want to allow this. When I protect the
sheet manually through Tools-->Protection-->Protect Sheet I can just
uncheck the boxes that say "select locked/unlocked cells" and its
protected the way I want. Is there a command I can use to have my macro
uncheck these options?
 
G

Gord Dibben

Jon

ActiveSheet.EnableSelection = xlNoSelection

If you record a macro while protecting the sheet and checking the appropriate
boxes, you will see the code used by Excel.


Gord Dibben Excel MVP
 
J

Jon

I tried that, it didnt seem to do anything. This may be because I save
and close the file I am protecting a the end of the macro. Does Excel
maybe forget that set the no selection option?
 

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