Notice: This website is an unofficial Microsoft Knowledge Base (hereinafter KB) archive and is intended to provide a reliable access to deleted content from Microsoft KB. All KB articles are owned by Microsoft Corporation. Read full disclaimer for more details.

XL2000: EnableSelection Property May Be Overridden


View products that this article applies to.

This article was previously published under Q213242

↑ Back to the top


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.

↑ Back to the top


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
				

↑ Back to the top


Resolution

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

↑ Back to the top


Status

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

↑ Back to the top


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.

↑ Back to the top


Keywords: KB213242, kbprogramming, kbpending, kbbug

↑ Back to the top

Article Info
Article ID : 213242
Revision : 6
Created on : 10/11/2006
Published on : 10/11/2006
Exists online : False
Views : 236