MrExcel Publishing
Your One Stop for Excel Tips & Solutions

EnableSelection = xlUnlockedCells, but then can't change locked cells


Posted by Geoff on January 02, 2002 5:45 AM

I have altered the EnableSelection in the WorkSheet Properties so only unprotected cells can be selected. However a combobox macro then falls over with "Runtime error 1004: unable to set the locked property of the Range class", when it tries to change protected cells to unprotected, via Selection.Locked = False.

I've tried putting a
With Worksheets(1)
.EnableSelection = xlNoRestrictions
End With

at the start of the ComboBox macro, but still falls over. Does anyone have any suggestions to a solution/point out where I'm going wrong?

Many thanks,
Geoff


Posted by Ivan F Moala on January 02, 2002 7:21 PM

Is the sheet protected ??


Ivan

Posted by Geoff on January 03, 2002 12:04 AM

Yes! so I guess my problem is how to unprotect it within Visual basic. The best Vbasic help could suggest it seems is
ActiveWorkbook.Protect Contents = False, but this doesn't work either. Any ideas?

CHeers,
Geoff

Posted by Ivan F Moala on January 03, 2002 12:12 AM

ActiveSheet.Unprotect
With Worksheets(1)
.EnableSelection = xlNoRestrictions
End With
ActiveSheet.Protect


If you have a password then

ActiveSheet.Unprotect password:="test"
With Worksheets(1)
.EnableSelection = xlNoRestrictions
End With
ActiveSheet.Protect password:="test"


Ivan

Posted by Geoff on January 03, 2002 6:42 AM

Sounded logical, but it still stumbles on

ActiveSheet.Unprotect

with error= Runtime error 1004: Unprotect method of worksheet failed

Any ideas why? I'll keep looking.
Cheers,
Geoff With Worksheets(1)