guliande 发表于 2010-6-3 12:00:00

[求助]《AutoCAD VBA & VB.NET开发基础与实例教程》 关于VBA增加菜单的问题

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

xiaowen 发表于 2010-6-9 15:55:00

<p>楼主能否上传此书给明经的兄弟们一起学习学习...答案还的高手来解决...</p>

guliande 发表于 2010-6-11 09:49:00

<p>不好意思,不是电子版的</p>
页: [1]
查看完整版本: [求助]《AutoCAD VBA & VB.NET开发基础与实例教程》 关于VBA增加菜单的问题