XL: Names.Add May Get Recorded Twice

Last reviewed: February 3, 1998
Article ID: Q159983
The information in this article applies to:
  • Microsoft Excel 98 Macintosh Edition
  • Microsoft Excel 97 for Windows
  • Microsoft Excel for Windows 95, versions 7.0, 7.0a
  • Microsoft Excel for Windows, versions 5.0, 5.0c
  • Microsoft Excel for the Macintosh, versions 5.0, 5.0a

SYMPTOMS

When you record a Microsoft Visual Basic for Applications macro that adds a defined name to a Microsoft Excel workbook, the following line of code may be recorded twice in the module:

   ActiveWorkbook.Names.Add Name:="DefinedName", RefersToR1C1:= _
      "=SheetName!Range"
   ActiveWorkbook.Names.Add Name:="DefinedName", RefersToR1C1:= _
      "=SheetName!Range"

where "DefinedName" refers to the name you typed in, "SheetName" is the name of your worksheet, and "Range" is the range of cells that "DefinedName" refers to.

CAUSE

This line of code gets recorded twice because it is defined once when the Add button in the Define Name dialog box is clicked and again when the OK button is clicked. Clicking both buttons accomplishes the same thing; they both assign the defined name.

RESOLUTION

If you want a recorded macro to record only one line of code for adding a single defined name to your workbook, click only the OK button in the Define Name dialog box when recording the macro. It is not necessary to click the Add button.

NOTE: If you are adding multiple defined names to your workbook, then click Add after entering the information for each defined name except the last name you add; click OK for the last defined name.

STATUS

This behavior is by design of Microsoft Excel.

REFERENCES

For more information about the Add Method of the Names Collection, click the Office Assistant, type "define name", click Search, and then click to view "Add Method (Names Collection)".


Additional query words: XL97 XL98 XL7 XL5
Keywords : xlvbainfo PgmOthr
Version : WINDOWS:5.0,5.0c,7.0,7.0a,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.