How to Delete and Restore a Menu That Has a Submenu (125423)



The information in this article applies to:

  • Microsoft Excel 97 for Windows
  • Microsoft Excel for Windows 95
  • Microsoft Excel for Windows 5.0

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


Modification Type:MinorLast Reviewed:10/10/2006
Keywords:kbdtacode kbhowto kbProgramming KB125423