XL2000: EnableSelection Property May Be Overridden (213242)



The information in this article applies to:

  • Microsoft Excel 2000

This article was previously published under Q213242

SYMPTOMS

In Microsoft Excel, when you use the Microsoft Visual Basic EnableSelection property to restrict certain cells in a worksheet from being selected, you may still be able to select the restricted cells. For example, if you use the following code in a macro to prevent selection of locked cells
Sub Test()
   With ActiveSheet
      .EnableSelection = xlUnlockedCells
      .Protect Contents:=True, UserInterfaceOnly:=True
   End With
End Sub
				
it may still be possible to select locked cells.

CAUSE

This occurs because the EnableSelection property does not always prevent you from selecting cells by using the Name box on the formula bar.

Also, you can use a macro to select cells, even if they are locked, by using a line of code similar to the following:
Range("B5").Select
				

RESOLUTION

Even though you can select restricted cells, if the cells are locked and the worksheet is protected, you cannot change them.

STATUS

Microsoft has confirmed that this is a problem in the Microsoft products that are listed at the beginning of this article.

MORE INFORMATION

You can use the Visual Basic EnableSelection property to determine what, if any, cells on a worksheet may be selected by the user. EnableSelection has three possible constants:
   Constant              Definition
   ---------------------------------------------------------------------

   xlNoRestrictions   Any cell can be selected.
   xlNoSelection      No cells can be selected.
   xlUnlockedCells    If the worksheet is protected, only cells that are
                      unlocked can be selected.
				
You can unlock a cell or group of cells by using the following steps:
  1. Select the cell(s) to be unlocked.
  2. On the Format menu, click Cells.
  3. On the Protection tab, click to clear the Locked check box, and then click OK.
If the worksheet is protected and you have set the EnableSelection property to xlUnlockedCells, you cannot select locked cells, either by clicking them with the mouse or by using the Go To dialog box on the Edit menu. However, you can select locked cells by using the Name box on the Excel formula bar.

If you click the Name box, type in a cell reference (D5, for example) or a range reference (D5:E10, for example), and then press ENTER, the indicated cell or range will be selected.

NOTE: Because the cells are locked and the worksheet protected, locked cells cannot be changed. You can, however, copy or fill from a locked cell into unlocked cells.

Modification Type:MinorLast Reviewed:10/11/2006
Keywords:kbbug kbpending kbProgramming KB213242