Lesnacklie 发表于 2006-5-18 19:04:00

求助!关于添加右键菜单选项的问题

<P>我把例子输进去,试了几个版本的例子,但总是执行到最后一步生成菜单选项的时候总是出现“对象变量和with块变量未设置”的提示,请问这是怎么回事,谢谢了。</P>

xinghesnak 发表于 2006-5-19 08:06:00

把你的程序贴上来吧!

Lesnacklie 发表于 2006-5-19 15:58:00

<P>Sub Ch_AddMenuItemToshortcutMenu()<BR>&nbsp;&nbsp;&nbsp; Dim currMenuGroup As AcadMenuGroup<BR>&nbsp;&nbsp;&nbsp; Set currMenuGroup = ThisDrawing.Application.MenuGroups.Item(0)</P>
<P>&nbsp;&nbsp;&nbsp; ' 查找快捷菜单并将其指定给<BR>&nbsp;&nbsp;&nbsp; ' shortcutMenu 变量<BR>&nbsp;&nbsp;&nbsp; Dim scMenu As AcadPopupMenu<BR>&nbsp;&nbsp;&nbsp; Dim entry As AcadPopupMenu<BR>&nbsp;&nbsp;&nbsp; For Each entry In currMenuGroup.Menus<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; If entry.ShortcutMenu = True Then<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Set scMenu = entry<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; End If<BR>&nbsp;&nbsp;&nbsp; Next entry</P>
<P>&nbsp;&nbsp;&nbsp; ' 向快捷菜单添加菜单项<BR>&nbsp;&nbsp;&nbsp; Dim newMenuItem As AcadPopupMenuItem<BR>&nbsp;&nbsp;&nbsp; Dim openMacro As String<BR>&nbsp;&nbsp;&nbsp; <BR>&nbsp;&nbsp;&nbsp; ' 给宏指定“ESC ESC _open”的 VBA 等价值<BR>&nbsp;&nbsp;&nbsp; <BR>&nbsp;&nbsp;&nbsp; openMacro = Chr(3) + Chr(3) + "_open "<BR>Dim a As Integer<BR>Dim b As String<BR>a = Asc("&amp;")<BR>b = Chr(95)<BR>&nbsp;&nbsp;&nbsp; Set newMenuItem = scMenu.AddMenuItem("", Chr(Asc("&amp;")) + "OpenDWG", openMacro)<BR>End Sub</P>
<P>真是太谢谢了</P>

xinghesnak 发表于 2006-5-19 16:34:00

<P>其实问题很简单,currMenuGroup得到的菜单组里没有快捷菜单,所以scMenu也就没有被赋值,自然到最后一句会报错。。。。(在我这就是这样)</P>
<P>不如把这句Dim currMenuGroup As AcadMenuGroup<BR>&nbsp;&nbsp;&nbsp; Set currMenuGroup = ThisDrawing.Application.MenuGroups.Item(0)</P>
<P>换成</P>
<P>&nbsp;&nbsp;&nbsp; Dim currMenuGroup As AcadMenuGroup<BR>&nbsp;&nbsp;&nbsp; For Each currMenuGroup In ThisDrawing.Application.MenuGroups<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; If currMenuGroup.Name = "AMDTPP" Then Exit For<BR>&nbsp;&nbsp;&nbsp; Next</P>

Lesnacklie 发表于 2006-5-19 19:21:00

<P>唉,小弟菜鸟,不明白,试了一下,还是有问题哦,运行到</P>
<P>For Each entry In currMenuGroup.Menus</P>
<P>这句时又出现对象变量或with块变量未设置,咋办呢</P>

xinghesnak 发表于 2006-5-20 08:12:00

没招了,在我这一切正常,没有报错。。。你替换那句话了吗?

houlinbo 发表于 2006-12-6 15:08:00

同问,急呀,好几天了这个问题,我的也出现同样的提示,根本通不过

流动的清泉 发表于 2017-12-26 22:19:00

没有 lisp的 程序吗

dong20030432 发表于 2018-1-10 13:17:45

原因是当你要运行这个过程的时候,根本就没有快捷菜单弹出,无法获取,当然就不能执行了。
页: [1]
查看完整版本: 求助!关于添加右键菜单选项的问题