我在书上找了段关于在右键菜单中增加条目的代码,可不知怎么回事,每次都需运行两次才能实现,希望高手指导,谢谢!- Sub Ch6_AddMenuItemToshortcutMenu()
- On Error Resume Next
- Dim currMenuGroup As AcadMenuGroup
- Set currMenuGroup = ThisDrawing.Application.MenuGroups.Item(0)
- '找到快捷菜单并赋值它为shortcutMenu变量
- 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
- ' 在快捷菜单中增加菜单项
- Dim newMenuItem As AcadPopupMenuItem
- Dim openMacro As String
- ' 为宏赋值VBA表达式"ESC ESC _open "
- openMacro = Chr(3) + Chr(3) + Chr(95) + "open" + Chr(32)
- Set newMenuItem = scMenu.AddMenuItem("", Chr(Asc("&")) + "OpenDWG", openMacro)
- End Sub
|