Protect sheets: The EnableSelection property is not saved + Excel update fix

Protect sheets: The EnableSelection property is not saved + Excel update fixYesterday I got the following question: "When using the 'protect multiple sheets at once and checking only the 'select unlocked cells checkbox I find that once I save and reopen the sheets now behave as if both the 'select unlocked cells as well as the 'select locked cells seems to be in effect as I can then select any cell, however, the rest of the protections seem to be in place."

At first I couldn't reproduce the problem, however when I did it on a computer with Excel 2003 without any service packs installed I could replicate the problem. At first it looks just right but when you save, close and re-open the file the setting of selecting only unlocked cells was lost. I found in the MS Knowledge base that this is a bug that is fortunately fixed in one of the Excel service packs. After I installed the service pack the utility worked as expected.

Microsoft has confirmed that this is a problem in Excel 2002 and 2003: KB918323

When you try to use a Microsoft Visual Basic for Applications (VBA) macro to set the EnableSelection property in Microsoft Excel 2002 or in Microsoft Office Excel 2003, the EnableSelection property is not saved. After the workbook is saved, closed, and then opened, cells that you expect to be locked can be selected.

If you set the EnableSelection property manually, the changes are saved. Additionally, locked cells cannot be selected when the workbook is opened.

More information about this Excel bug in Excel 2002/XP and 2003:
http://support.microsoft.com/kb/918323/en-us (page no longer available)

Excel 2002 post-Service Pack 3 hotfix package: May 6, 2004
http://support.microsoft.com/kb/829348/ (page no longer available)

Description of the Excel 2003 post-Service Pack 1 hotfix package: August 20, 2004
http://support.microsoft.com/kb/840316/ (page no longer available)

Office update

To download the service pack from Office Update, visit the following Microsoft Web site:
https://support.microsoft.com/en-us/office/install-office-updates-2ab296f3-7f03-43a2-8e50-46de917611c5

Excel 2007

Unfortunately this bug also exists in Excel 2007 (12.0.4518 and 12.0.6024) and I haven't seen a fix for this. I also found out that if you save the file as an Excel 97-2003 workbook, the selection restrictions will be saved. However if you save the file in 2007 format the setting is lost. Protecting one sheet at a time manually works. However doing it with a macro still has issues in Excel 2007...

Here is an code example:

Sub UnProtectAllSheets()
' Unprotect all sheets without a password
' also resets the selection restriction
Dim i                                                As Long
For i = 1 To ActiveWorkbook.Sheets.Count
Sheets(i).Unprotect
Sheets(i).EnableSelection = xlNoRestrictions
Next i
End Sub

Sub ProtectAllSheets()
' Protect all sheets without a password
' allow only the selection of unlocked cells
Dim i                                                As Long
For i = 1 To ActiveWorkbook.Sheets.Count
Sheets(i).Protect DrawingObjects:=True, Contents:=True, Scenarios:=True
Sheets(i).EnableSelection = xlUnlockedCells
Next i
End Sub