Article ID: 160520 - Last Review: November 23, 2006 - Revision: 2.4 XL97: Error Adding or Deleting a Menu Command in a MacroThis article was previously published under Q160520 SYMPTOMS
In Microsoft Excel 97, if you run a Visual Basic for Applications macro
that adds a command to a menu or deletes a command from a menu, you may
receive the following error message:
Run-time error '1004': Application-defined or object-defined error CAUSE
This behavior occurs when, in the macro command to add or delete the menu
command, you specify a menu command that no longer exists, or is changed in
Microsoft Excel 97.
This behavior is by design of Microsoft Excel. For a list of the menu commands that are changed in Microsoft Excel 97, see the "More Information" section in this article. WORKAROUNDMicrosoft 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 professionals 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 a Microsoft Certified Partner or Microsoft Advisory Services. For more information, visit these Microsoft Web sites: Microsoft Certified Partners - https://partner.microsoft.com/global/30000104 (https://partner.microsoft.com/global/30000104) Microsoft Advisory Services - http://support.microsoft.com/gp/advisoryservice (http://support.microsoft.com/gp/advisoryservice) For more information about the support options that are available and about how to contact Microsoft, visit the following Microsoft Web site:http://support.microsoft.com/default.aspx?scid=fh;EN-US;CNTACTMS (http://support.microsoft.com/default.aspx?scid=fh;en-us;cntactms) To work around this behavior, use either of the following methods:
However, the following macro works correctly in all versions of Microsoft Excel: MORE INFORMATION
In Microsoft Excel, in a Visual Basic macro, you can add a new menu command
to a menu by using a line of code similar to the following:
You can also delete a menu command by using a line of code similar to the following: The two lines of code work correctly in earlier versions of Microsoft Excel. However, they do not work correctly in Microsoft Excel 97, because the menu command "Toolbars..." is renamed Toolbars (no ellipsis). The following menu commands are changed in Microsoft Excel 97. Microsoft Excel 5.0, 7.0 Microsoft Excel 97 Menu menu command menu command -------------------------------------------------------------- View Toolbars... Toolbars Insert Chart Chart... Insert Note... Comment Data PivotTable... PivotTable Report... sheet tab Rename... Rename shortcut menu* | Article Translations
|

Back to the top
