Microsoft KB Archive/125423

From BetaArchive Wiki

Article ID: 125423

Article Last Modified on 10/10/2006



APPLIES TO

  • Microsoft Excel 97 Standard Edition
  • Microsoft Excel 95 Standard Edition
  • Microsoft Excel 5.0 Standard Edition



This article was previously published under Q125423

For a Microsoft 2000 version of this article, see 213437.


SUMMARY

In a Visual Basic for Applications macro, if you delete a menu item that has a submenu and you want to restore it, use the Addmenu command, not the Add command. Addmenu adds a new menu (or submenu), while Add adds a new menu item.

MORE INFORMATION

Microsoft provides programming examples for illustration only, without warranty either expressed or implied. This includes, but is not limited to, the implied warranties of merchantability or fitness for a particular purpose. This article assumes that you are familiar with the programming language that is being demonstrated and with the tools that are used to create and to 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 requirements. The following Visual Basic procedure restores a menu item that has a submenu.

Sample Visual Basic Procedure

If you want to delete the Protection submenu from the Tools menu, use the following code:

      Sub DeleteIt()
      MenuBars(xlWorksheet).Menus("Tools").MenuItems("Protection").Delete
   End Sub

If you then want to restore the Protection submenu to the Tools menu, use
the following code:

   Sub AddItBack()
      MenuBars(xlWorksheet).Menus("Tools").MenuItems.AddMenu _
         Caption:="Protection", restore:=True, before:="Add-Ins..."
   End Sub
                

REFERENCES

For additional information about getting help with Visual Basic for Applications, please see the following article in the Microsoft Knowledge Base:

163435 VBA: Programming Resources for Visual Basic for Applications



Additional query words: 5.00a 5.00c 7.00a 97 XL97 XL7 XL5 XL

Keywords: kbdtacode kbhowto kbprogramming KB125423