XL: Cannot Define Name If Active Sheet Protected

Last reviewed: February 3, 1998
Article ID: Q108359

The information in this article applies to:
  • Microsoft Excel for Windows, versions 5.0, 5.0c
  • Microsoft Excel for the Macintosh, versions 5.0, 5.0a
  • Microsoft Excel for Windows 95, versions 7.0, 7.0a
  • Microsoft Excel 97 for Windows
  • Microsoft Excel 98 Macintosh Edition

SYMPTOMS

In Microsoft Excel, if the active sheet and its contents are protected, you may not be able to do either of the following:

  • Define a name by pointing to Name on the Insert menu and then clicking Define.

        -or-
    
  • Add a name anywhere in the workbook by using the Visual Basic for Applications Names.Add method or the Microsoft Excel 4.0 DEFINE.NAME() macro command. This applies only to Microsoft Excel for Windows, version 5.0.

MORE INFORMATION

Microsoft provides programming examples for illustration only, without warranty either expressed or implied, including, but not limited to, the implied warranties of merchantability and/or fitness for a particular purpose. This article assumes that you are familiar with the programming language being demonstrated and the tools used to create and debug procedures. Microsoft support engineers can help explain the functionality of a particular procedure, but they will not modify these examples to provide added functionality or construct procedures to meet your specific needs. If you have limited programming experience, you may want to contact the Microsoft fee-based consulting line at (800) 936-5200. For more information about the support options available from Microsoft, please see the following page on the World Wide Web:

   http://www.microsoft.com/support/supportnet/refguide/default.asp

To define a name when the active sheet and its contents are protected, follow the appropriate procedure below.

Manually Define the Name

Use the name box on the left side of the formula bar. For example, to define the new global name "Test" when the active sheet and its contents are protected:

  1. Select the range to which "Test" should refer.

  2. In the name box, type "Test" (without the quotation marks) and press ENTER to define the name.

To define a local name, include the sheet's name in the name box. For example type, "Sheet1!Test" or "Sheet2!Sample".

NOTE: To protect a worksheet and prevent names from being created using the name box, disable the formula bar.

NOTE: You cannot use this method to define a name in Microsoft Excel 97 or Microsoft Excel 98 Macintosh Edition when the active sheet is protected.

Use Code to Define the Name

Using the Names.Add method or the DEFINE.NAME() macro command to define a name, you must first activate an unprotected sheet or unprotect the active sheet.

If you want to add a defined name without unprotecting the worksheet, use code similar to the following sample Visual Basic for Applications macro.

   Sub Insert_Name()

       'This will define the range A1:A5 on the active sheet
       'to the name "test".
       ActiveSheet.Range("A1:A5").Name = "test"

   End Sub

Run the macro "Insert_Name" and the range A1:A5 will be defined as "test" (without the quotation marks).

NOTE: In Microsoft Excel versions 5.0c and later, you can use a Visual Basic subroutine or Microsoft Excel 4.0 macro to define a name on a protected worksheet without first unprotecting the worksheet. The workaround shown above is necessary only in Microsoft Excel for Windows, version 5.0.

REFERENCES

"User's Guide," version 5.0, pages 688-692


Additional query words: 5.00 7.00 XL98 XL97 XL7 XL5
Keywords : kbcode kbprg PgmOthr
Version : WINDOWS:5.0,5.0c,7.0,97; MACINTOSH:5.0,98
Platform : MACINTOSH WINDOWS
Issue type : kbprb
Solution Type : kbworkaround


THE INFORMATION PROVIDED IN THE MICROSOFT KNOWLEDGE BASE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. MICROSOFT DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING THE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL MICROSOFT CORPORATION OR ITS SUPPLIERS BE LIABLE FOR ANY DAMAGES WHATSOEVER INCLUDING DIRECT, INDIRECT, INCIDENTAL, CONSEQUENTIAL, LOSS OF BUSINESS PROFITS OR SPECIAL DAMAGES, EVEN IF MICROSOFT CORPORATION OR ITS SUPPLIERS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. SOME STATES DO NOT ALLOW THE EXCLUSION OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES SO THE FOREGOING LIMITATION MAY NOT APPLY.

Last reviewed: February 3, 1998
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.