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:
- 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.)
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:
- On a new worksheet, use the Rectangle or Filled Rectangle drawing tool to draw a rectangle.
- With the rectangle selected, type the name "Square" (without the quotation marks) in the name box and press ENTER.
- In cell A1, type the word "Test" (without the quotation marks).
- From the Insert menu, choose name, and then choose Define.
- 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 Last reviewed: March 27, 1997 |