A macro is a series of commands that executes specific actions when a menu item is selected. Menu macros can simply be recordings of keystrokes that accomplish a task, or they can be a complex combination of commands, AutoLISP, DIESEL, or ActiveX programming code.
Once a menu item has been created, you can change the macro for the menu item using the Macro property.
Add menu items to a popup menu
This example creates a new menu called “TestMenu” and inserts a menu item. The menu item is given the name “Open,” and the macro assigned to the menu item is the OPEN command.
Sub Ch6_AddAMenuItem()
Dim currMenuGroup As AcadMenuGroup
Set currMenuGroup = ThisDrawing.Application.MenuGroups.Item(0)
' Create the new menu
Dim newMenu As AcadPopupMenu
Set newMenu = currMenuGroup.Menus.Add("TestMenu")
' Add a menu item to the new menu
Dim newMenuItem As AcadPopupMenuItem
Dim openMacro As String
' Assign the macro the VBA equivalent of "ESC ESC _open "
openMacro = Chr(3) + Chr(3) + "_open "
Set newMenuItem = newMenu.AddMenuItem _
(newMenu.count + 1, "Open", openMacro)
' Display the menu on the menu bar
newMenu.InsertInMenuBar _
(ThisDrawing.Application.menuBar.count + 1)
End Sub