About Deleting Menu Items from a Menu (VBA/ActiveX)

To remove menu items from a menu, use the Delete method found on the menu item.

Caution: If you delete a menu item, do not call another method or property that would directly or indirectly cause the same CUIx file to be loaded again within the same macro. For example, after deleting a menu item, do not use the MenuGroup.Load method or the Preferences.Profiles.ActiveProfile property, or issue the AutoCAD CUILOAD command using the Document.SendCommand method. These items directly or indirectly cause the loading of CUIx files. You should only use these methods or properties in a separate macro.

Delete a menu item from a menu

This example adds a menu item to the end of the last menu displayed on the menu bar. It then deletes the menu item.

Sub Ch6_DeleteMenuItem()
 Dim LastMenu As AcadPopupMenu
 Set LastMenu = ThisDrawing.Application.menuBar. _
 Item(ThisDrawing.Application.menuBar.count - 1)

 ' Add a menu item
 Dim newMenuItem As AcadPopupMenuItem
 Dim openMacro As String
 ' Assign the macro the VB equivalent of "ESC ESC _open "
 openMacro = Chr(3) + Chr(3) + "_open "

 Set newMenuItem = LastMenu.AddMenuItem _
 (LastMenu.count + 1, "Open", openMacro)

 ' Remove the menu item from the menu
 newMenuItem.Delete
End Sub