To insert an existing menu in the menu bar, use the InsertMenuInMenuBar or the InsertInMenuBar method. Both methods accomplish the same goal—they insert an existing menu into the menu bar.
The difference between the two methods is the object from which they are called. The InsertMenuInMenuBar method is called from the PopupMenus collection. Using this method you can insert any menu from the collection into a specified location on the menu bar. This method requires as input the name of the menu to insert and the location on the menu bar to insert it.
The InsertInMenuBar method is called directly from the PopupMenu object to be inserted. The only input this method requires is a location on the menu bar. The name of the menu is not needed because you are calling the method directly from the object to be inserted.
You should use whichever method is more convenient for your application.
This example creates a new menu called TestMenu and inserts a menu item into it. The menu item is assigned the OPEN command. The menu is then displayed on the menu bar.
Sub Ch6_InsertMenu()
' Define a variable for the current menu group
Dim currMenuGroup As AcadMenuGroup
Set currMenuGroup = ThisDrawing.Application. _
MenuGroups.Item(0)
' Create a new menu
Dim newMenu As AcadPopupMenu
Set newMenu = currMenuGroup.Menus.Add("TestMenu")
' Declare the variables for the menu item
Dim newMenuItem As AcadPopupMenuItem
Dim openMacro As String
' Assign the macro string the VB equivalent of
' "ESC ESC _open " and create the menu item
openMacro = Chr(3) + Chr(3) + "_open "
Set newMenuItem = newMenu.AddMenuItem(newMenu.Count + 1, _
"Open", openMacro)
' Display the menu on the menu bar
currMenuGroup.Menus.InsertMenuInMenuBar "TestMenu", ""
End Sub