Protecting Specified Data Using VBA
February 12, 2002 - by Juan Pablo Gonzalez
Anthony asks:
When selecting the '0 -xlUnlockedCells' properity in the EnableSelection window only the unlocked cells can be selected when the workbook is protected. However, when the workbook is Saved, Closed and then re-opened the EnableSelection defaults back to '0 -xlNoRestrictions' how can I stop this happening? Regards.
Well, this can be solved using some events. One, using the Workbook_Open event, or two, using the Sheet_Activate event, like this:
In the workbook Module
Private Sub Workbook_Open()
Sheets("Sheet1").EnableSelection = xlUnlockedCells
End Sub
or in the Sheet's Module
Private Sub Worksheet_Activate()
ActiveSheet.EnableSelection = xlUnlockedCells
End Sub
One final thing, xlUnlockedCells equals 1. 0 is xlNoRestrictions and -4142 is xlNoSelection.