Registrations are now open. Join us today!
There is still a lot of work to do on the wiki yet! More information about editing can be found here.
Already have an account?

Microsoft KB Archive/105769

From BetaArchive Wiki

Microsoft Knowledge Base

XL: Can Use Same Name to Define Object and Defined Name

Last reviewed: March 27, 1997
Article ID: Q105769

5.00 5.00c 7.00 | 5.00

WINDOWS         | MACINTOSH

kbusage kbtlc

The information in this article applies to:

  • Microsoft Excel for Windows, versions 5.0, 5.0c
  • Microsoft Excel for Windows 95, version 7.0
  • Microsoft Excel for Windows NT, version 5.0
  • Microsoft Excel for the Macintosh, version 5.0

SUMMARY

Microsoft Excel versions 5.0 and 7.0 store object names and defined names in separate locations in memory. This method of storing names means that a defined name and a named object on the same worksheet can have the same name.

MORE INFORMATION

Microsoft Excel versions 5.0 and 7.0 allow you to rename objects such as drawn objects, Visual Basic controls, and bitmaps. To rename an object:

  1. Select the object. (Some objects, such as buttons and Visual Basic controls, may require that you hold down the CTRL key while you select the object.)
  2. In the name box, type the new name of the object and press ENTER.

    Note that naming the object in this way is NOT the same as naming it by using the Define Name dialog box.

    When the object is selected, you will see the object's new name in the name list.

To create an example of a named object and a named range that have the same name, do the following:

  1. On a new worksheet, use the Rectangle or Filled Rectangle drawing tool to draw a rectangle.
  2. With the rectangle selected, type the name "Square" (without the quotation marks) in the name box and press ENTER.
  3. In cell A1, type the word "Test" (without the quotation marks).
  4. From the Insert menu, choose name, and then choose Define.
  5. In the Names In Workbook box, type "Square" (without the quotation marks) and choose OK.

When cell A1 is selected, the name Square will appear in the name box. Similarly, when you select the rectangle, Square will appear in the name box.

Although the name box will display the name of an object when the object is selected, it cannot be used to select an object. Using the above example, if you select the name Square from the name box, the cell named Square will be selected, not the Square object. You can still select the object by clicking it with your mouse.

How to Refer to Named Objects and Defined Names in Visual Basic Code

If you are writing a Visual Basic macro, you could use this code to select the object Square:

   ActiveSheet.Rectangles("Square").Select

To select the range Square, you could use this code:

   Range("Square").Select

Because you are able to specify different objects ('Rectangles' versus

'Range'), you are able to select the proper items, even though they

have the same name.

REFERENCES

"User's Guide," version 5.0, Chapters 10 and 13


KBCategory: kbusage kbtlc

KBSubcategory:

Additional reference words: 5.00 5.00a 5.00c 7.00 define.name
Keywords : kbtlc kbusage
Version : 5.00 5.00c 7.00 | 5.00
Platform : MACINTOSH WINDOWS


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: March 27, 1997
©1997 Microsoft Corporation. All rights reserved. Legal Notices.