About Adding Entries to the Right-Click Menu (VBA/ActiveX)

The right-click menu, or shortcut menu, is a special menu included in the AutoCAD base menu group. This menu appears when the user holds Shift and clicks the right mouse button.

AutoCAD finds the shortcut menu by looking in the base menu group for a menu with the ShortcutMenu property equal to TRUE.

New menu groups may or may not have a shortcut menu available. To create a shortcut menu for a menu group, create a new menu and use POP0 as the label for the new menu.

Add a menu item to the end of the right-click menu

This example adds the menu item “OpenDWG” to the end of the right-click menu.

Sub Ch6_AddMenuItemToshortcutMenu()
 Dim currMenuGroup As AcadMenuGroup
 Set currMenuGroup = ThisDrawing.Application.MenuGroups.Item(0)

 ' Find the shortcut menu and assign it to the
 ' shortcutMenu variable
 Dim scMenu As AcadPopupMenu
 Dim entry As AcadPopupMenu
 For Each entry In currMenuGroup.Menus
 If entry.shortcutMenu = True Then
 Set scMenu = entry
 End If
 Next entry

 ' Add a menu item to the shortcut 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 = scMenu.AddMenuItem _
 ("", Chr(Asc("&")) _
 + "OpenDWG", openMacro)
End Sub