P257 :代码如下,运行后报错:运行时错误,菜单组中存在弹出菜单。
当然这个错误书中也提及了 不过“因为时间所迫,没有找到合适的解决方案”。哪位高手可以帮忙看下~~谢谢
Public Sub AddMenu()
'获得当前的菜单组
Dim currMenuGroup As AcadMenuGroup
Set currMenuGroup = ThisDrawing.Application.MenuGroups.Item(0) ''''这里为什么是Item(0) 啊。
'''创建菜单
Dim newMenu As AcadPopupMenu
Set newMenu = currMenuGroup.Menus.Add("MyMen" & Chr(Asc("&")) & "u")
'''''添加菜单项
Dim macro As String
marco = Chr(vbKeyEscape) + Chr(vbKeyEscape) ''''''相等与按下两次Esc
'''
''''Open 菜单项
Dim menuItem As AcadPopupMenuItem
Set menuItem = newMenu.AddMenuItem(newMenu.Count + 1, Chr(Asc("&")) & "OpenFile", macro & "_open")
menuItem.HelpString = "打开图形文件\VBA精彩实例"
''''CLose菜单项
Set menuItem = newMenu.AddMenuItem(newMenu.Count + 1, Chr(Asc("&")) & "CloseFile", macro & "_close")
menuItem.HelpString = "关闭图形文件\VBA精彩实例"
'''''分割线
Set menuItem = newMenu.AddSeparator("")
''''draw(含有子菜单)
Dim menuDraw As AcadPopupMenu
Set menuDraw = newMenu.AddSubMenu(newMenu.Count + 1, Chr(Asc("&")) & "Draw")
''''''子菜单项目 line
Dim subMenuItem As AcadPopupMenuItem
Set subMenuItem = menuDraw.AddMenuItem(menuDraw.Count + 1, Chr(Asc("&")) & "Line", macro & "_Line")
'''''''子菜单项目 Arc
Set subMenuItem = menuDraw.AddMenuItem(menuDraw.Count + 1, Chr(Asc("&")) & "Arc", macro & "_Arc")
'''''''子菜单项目 Circle
Set subMenuItem = menuDraw.AddMenuItem(menuDraw.Count + 1, Chr(Asc("&")) & "Circle", macro & "-vbarun" + Chr(32) + "ThisDrawing.DrawCircle" + Chr(32))
''''''dimension (含有子菜单)
Dim menuDim As AcadPopupMenu
Set menuDim = newMenu.AddSubMenu(newMenu.Count + 1, "Dimension" & Chr(Asc("&")) & "n")
''''''子菜单项目 dimAligned
Set subMenuItem = menuDim.AddMenuItem(menuDim.Count + 1, "DimAli" & Chr(Asc("&")) & "gned", macro & "_DimAligned")
''''''子菜单项目 dim linear
Set subMenuItem = menuDim.AddMenuItem(menuDim.Count + 1, "Dim" & Chr(Asc("&")) & "Ordinate", macro & "_DimLinear")
'''''''子菜单项目 dimOrdinate
Set subMenuItem = menuDim.AddMenuItem(menuDim.Count + 1, "Dim" & Chr(Asc("&")) & "Ordinate", macro & "_DimOrdinate")
'''''''在菜单上显示菜单
newMenu.InsertInMenuBar ThisDrawing.Application.MenuBar.Count + 1
'''查找快捷键
Dim scMenu As AcadPopupMenu
Dim element As AcadPopupMenu
Set currMenuGroup = ThisDrawing.Application.MenuGroups.Item(1)
For Each element In currMenuGroup.Menus
If element.ShortcutMenu = True Then
Set scMenu = element
Exit For
End If
Next element
''''为快捷菜单添加菜单项-测量距离()
Dim scMenuItem As AcadPopupMenuItem
Set scMenuItem = scMenu.AddMenuItem(scMenu.Count, "测量距离(&D)", macro & "_Dist")
End Sub |