deng163 发表于 2006-4-24 15:16:00

[VBA]怪!这段程序为什么要运行两次才能实现?

我在书上找了段关于在右键菜单中增加条目的代码,可不知怎么回事,每次都需运行两次才能实现,希望高手指导,谢谢!
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

deng163 发表于 2006-4-26 19:16:00

<P></P>
<P>难道就没人查出哪出错了吗?或者程序本身就没问题,是我的cad没装好?</P>
<P>HELP!</P>

ghosthsg 发表于 2006-4-27 09:31:00

<P>你把第四行的定义改为:</P>
<P>Set currMenuGroup = acadapp.MenuGroups.Item(0)</P>
<P>试试!</P>

xxsheng 发表于 2006-4-27 11:17:00

scMenu.AddMenuItem,你跟踪下程序,我的系统autocad2002跟踪下,第一次运行scmenu总是空,scMenu.AddMenuItem当然也就不能实现,,,,,,
页: [1]
查看完整版本: [VBA]怪!这段程序为什么要运行两次才能实现?