烤烟农民 发表于 2005-7-2 17:08:00

怎么自动激活宏??

<FONT class=topic size=3>小弟在绘图栏制作了一个小按纽,连接了一个宏代码.但是每次电击按纽的时候,总是出现一个对话框,大意是选择加载宏.当我选择了加载宏后,点击连接宏的按钮,还是出现相同的对话框,还是选择加载宏,每次都这样.搞的我很郁闷~~~当加载后,如果从菜单栏里面的工具栏选择运行宏,才可以正常运行宏.我希望的效果是:当我点击自做的宏按纽后,能够想那些画直线,圆什么的CAD按钮,不需要在人工加载,就可以直接运行.请高手指点,万分感谢!!!!<IMG alt=微笑 src="http://abbs.cn/images/smiles/smile.gif" width=15> </FONT><BR><BR>

LucasLynn 发表于 2005-7-2 19:04:00

如果是VBA写的宏,直接把他加入acad.dvb里面。系统才能自动加载。

烤烟农民 发表于 2005-7-6 21:10:00

就这么简单??回去试试,呵呵。。谢谢上面的朋友。

y1982_0 发表于 2005-7-6 23:06:00

晚上刚做的这个东西,你把自己的工程存到AUTOCAD文件夹下的support目录下,起名叫acad.dvb,就可以自动加载,多说一句,如果想自动运行宏,就在这个目录下健个文件,叫acad###.dls,里面写两句代码就行了,我忘了,你查查,肯定好用

烤烟农民 发表于 2005-7-29 21:44:00

<P>关键处呀,里面两句代码是什么呀??请指教,谢谢.</P>

雪山飞狐_lzh 发表于 2005-7-29 22:06:00

<P>直接用</P>
<P>“文件名!模块名.宏名”的方式调用</P>
<P>比如下面表示my.dvb的mShare模块下的Test宏:</P>
<P>my.dvb!mShare.Test</P>

cenyong 发表于 2005-9-6 14:40:00

<STRONG>用按钮来运行VBA工程<BR></STRONG>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; WORD-BREAK: break-all; TEXT-INDENT: 28pt; TEXT-ALIGN: left; mso-pagination: widow-orphan; mso-margin-top-alt: auto; mso-margin-bottom-alt: auto; mso-char-indent-count: 2.0; mso-line-height-alt: 13.0pt" align=left>谨以本人在农村电气信息化上发表的“如何在CAD图纸中快速插入杆号”一文中编的宏为例(此宏经本人多次修改,并请高手指点),以下是操作步骤:<BR>1、打开AUTOCAD2004,单击菜单栏上的“工具”菜单、指向“宏”、单击Visual Basic编辑器进入VB编辑状态。 <BR>2、在VB编辑状态单击菜单栏上的“插入”菜单、单击“模块”,在编辑窗口中输入以下代码: <?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /><o:p></o:p></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; WORD-BREAK: break-all; TEXT-INDENT: 28pt; TEXT-ALIGN: left; mso-pagination: widow-orphan; mso-margin-top-alt: auto; mso-margin-bottom-alt: auto; mso-char-indent-count: 2.0; mso-line-height-alt: 13.0pt" align=left>Public Sub insertgh()<o:p></o:p></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; WORD-BREAK: break-all; TEXT-INDENT: 28pt; TEXT-ALIGN: left; mso-pagination: widow-orphan; mso-margin-top-alt: auto; mso-margin-bottom-alt: auto; mso-char-indent-count: 2.0; mso-line-height-alt: 13.0pt" align=left>Dim sp(0 To 2) As Double<o:p></o:p></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; WORD-BREAK: break-all; TEXT-INDENT: 28pt; TEXT-ALIGN: left; mso-pagination: widow-orphan; mso-margin-top-alt: auto; mso-margin-bottom-alt: auto; mso-char-indent-count: 2.0; mso-line-height-alt: 13.0pt" align=left>Dim textHeight As Double<o:p></o:p></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; WORD-BREAK: break-all; TEXT-INDENT: 28pt; TEXT-ALIGN: left; mso-pagination: widow-orphan; mso-margin-top-alt: auto; mso-margin-bottom-alt: auto; mso-char-indent-count: 2.0; mso-line-height-alt: 13.0pt" align=left>Dim textStr As String<o:p></o:p></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; WORD-BREAK: break-all; TEXT-INDENT: 28pt; TEXT-ALIGN: left; mso-pagination: widow-orphan; mso-margin-top-alt: auto; mso-margin-bottom-alt: auto; mso-char-indent-count: 2.0; mso-line-height-alt: 13.0pt" align=left>Dim textObj As AcadText<o:p></o:p></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; WORD-BREAK: break-all; TEXT-INDENT: 28pt; TEXT-ALIGN: left; mso-pagination: widow-orphan; mso-margin-top-alt: auto; mso-margin-bottom-alt: auto; mso-char-indent-count: 2.0; mso-line-height-alt: 13.0pt" align=left>Dim gh As Integer<o:p></o:p></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; WORD-BREAK: break-all; TEXT-INDENT: 28pt; TEXT-ALIGN: left; mso-pagination: widow-orphan; mso-margin-top-alt: auto; mso-margin-bottom-alt: auto; mso-char-indent-count: 2.0; mso-line-height-alt: 13.0pt" align=left>Dim varRet As Variant<o:p></o:p></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; WORD-BREAK: break-all; TEXT-INDENT: 28pt; TEXT-ALIGN: left; mso-pagination: widow-orphan; mso-margin-top-alt: auto; mso-margin-bottom-alt: auto; mso-char-indent-count: 2.0; mso-line-height-alt: 13.0pt" align=left>On Error GoTo Err_Control<o:p></o:p></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; WORD-BREAK: break-all; TEXT-INDENT: 28pt; TEXT-ALIGN: left; mso-pagination: widow-orphan; mso-margin-top-alt: auto; mso-margin-bottom-alt: auto; mso-char-indent-count: 2.0; mso-line-height-alt: 13.0pt" align=left>gh = ThisDrawing.Utility.GetInteger(vbCrLf &amp; "命令:请输入起始杆号:")<o:p></o:p></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; WORD-BREAK: break-all; TEXT-INDENT: 28pt; TEXT-ALIGN: left; mso-pagination: widow-orphan; mso-margin-top-alt: auto; mso-margin-bottom-alt: auto; mso-char-indent-count: 2.0; mso-line-height-alt: 13.0pt" align=left>textHeight = ThisDrawing.Utility.GetInteger("请输入文字高度:")<o:p></o:p></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; WORD-BREAK: break-all; TEXT-INDENT: 28pt; TEXT-ALIGN: left; mso-pagination: widow-orphan; mso-margin-top-alt: auto; mso-margin-bottom-alt: auto; mso-char-indent-count: 2.0; mso-line-height-alt: 13.0pt" align=left>&nbsp;Do While gh<o:p></o:p></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; WORD-BREAK: break-all; TEXT-INDENT: 28pt; TEXT-ALIGN: left; mso-pagination: widow-orphan; mso-margin-top-alt: auto; mso-margin-bottom-alt: auto; mso-char-indent-count: 2.0; mso-line-height-alt: 13.0pt" align=left>&nbsp;&nbsp;&nbsp; varRet = ThisDrawing.Utility.GetPoint(, "请选择插入点:")<o:p></o:p></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; WORD-BREAK: break-all; TEXT-INDENT: 28pt; TEXT-ALIGN: left; mso-pagination: widow-orphan; mso-margin-top-alt: auto; mso-margin-bottom-alt: auto; mso-char-indent-count: 2.0; mso-line-height-alt: 13.0pt" align=left>&nbsp;&nbsp;&nbsp; sp(0) = varRet(0)<o:p></o:p></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; WORD-BREAK: break-all; TEXT-INDENT: 28pt; TEXT-ALIGN: left; mso-pagination: widow-orphan; mso-margin-top-alt: auto; mso-margin-bottom-alt: auto; mso-char-indent-count: 2.0; mso-line-height-alt: 13.0pt" align=left>&nbsp;&nbsp;&nbsp; sp(1) = varRet(1)<o:p></o:p></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; WORD-BREAK: break-all; TEXT-INDENT: 28pt; TEXT-ALIGN: left; mso-pagination: widow-orphan; mso-margin-top-alt: auto; mso-margin-bottom-alt: auto; mso-char-indent-count: 2.0; mso-line-height-alt: 13.0pt" align=left>&nbsp;&nbsp;&nbsp; sp(2) = varRet(2)<o:p></o:p></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; WORD-BREAK: break-all; TEXT-INDENT: 28pt; TEXT-ALIGN: left; mso-pagination: widow-orphan; mso-margin-top-alt: auto; mso-margin-bottom-alt: auto; mso-char-indent-count: 2.0; mso-line-height-alt: 13.0pt" align=left>&nbsp;&nbsp;&nbsp; textStr = CStr(gh) &amp; "#"<o:p></o:p></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; WORD-BREAK: break-all; TEXT-INDENT: 28pt; TEXT-ALIGN: left; mso-pagination: widow-orphan; mso-margin-top-alt: auto; mso-margin-bottom-alt: auto; mso-char-indent-count: 2.0; mso-line-height-alt: 13.0pt" align=left>&nbsp;&nbsp;&nbsp; Set textObj = ThisDrawing.ModelSpace.AddText(textStr, sp, textHeight)<o:p></o:p></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; WORD-BREAK: break-all; TEXT-INDENT: 28pt; TEXT-ALIGN: left; mso-pagination: widow-orphan; mso-margin-top-alt: auto; mso-margin-bottom-alt: auto; mso-char-indent-count: 2.0; mso-line-height-alt: 13.0pt" align=left>&nbsp;&nbsp;&nbsp; gh = gh + 1<o:p></o:p></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; WORD-BREAK: break-all; TEXT-INDENT: 28pt; TEXT-ALIGN: left; mso-pagination: widow-orphan; mso-margin-top-alt: auto; mso-margin-bottom-alt: auto; mso-char-indent-count: 2.0; mso-line-height-alt: 13.0pt" align=left>&nbsp; Loop<o:p></o:p></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; WORD-BREAK: break-all; TEXT-INDENT: 28pt; TEXT-ALIGN: left; mso-pagination: widow-orphan; mso-margin-top-alt: auto; mso-margin-bottom-alt: auto; mso-char-indent-count: 2.0; mso-line-height-alt: 13.0pt" align=left>Err_Control:<o:p></o:p></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; WORD-BREAK: break-all; TEXT-INDENT: 28pt; TEXT-ALIGN: left; mso-pagination: widow-orphan; mso-margin-top-alt: auto; mso-margin-bottom-alt: auto; mso-char-indent-count: 2.0; mso-line-height-alt: 13.0pt" align=left>&nbsp; Err.Clear<o:p></o:p></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; WORD-BREAK: break-all; TEXT-INDENT: 28pt; TEXT-ALIGN: left; mso-pagination: widow-orphan; mso-margin-top-alt: auto; mso-margin-bottom-alt: auto; mso-char-indent-count: 2.0; mso-line-height-alt: 13.0pt" align=left>&nbsp; Exit Sub<o:p></o:p></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; WORD-BREAK: break-all; TEXT-INDENT: 42pt; TEXT-ALIGN: left; mso-pagination: widow-orphan; mso-margin-top-alt: auto; mso-margin-bottom-alt: auto; mso-char-indent-count: 3.0; mso-line-height-alt: 13.0pt" align=left>End Sub<o:p></o:p></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; WORD-BREAK: break-all; TEXT-ALIGN: left; mso-pagination: widow-orphan; mso-margin-top-alt: auto; mso-margin-bottom-alt: auto; mso-line-height-alt: 13.0pt" align=left>3、保存上述代码,(必须)为它重新取个工程名称:insertgh.dvb,保存在AUTOCAD&nbsp;&nbsp;2004安装目录的Support文件夹,返回AUTOCAD工作界面。<o:p></o:p></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; WORD-BREAK: break-all; TEXT-ALIGN: left; mso-pagination: widow-orphan; mso-margin-top-alt: auto; mso-margin-bottom-alt: auto; mso-line-height-alt: 13.0pt" align=left>4、用鼠标右键单击“绘图”工具栏,然后从弹出的快捷菜单中选择“自定义”选项,打开“自定义”对话框。单击“命令”选项卡,先选中对话框“分类”列表的用户定义,然后在“命令”列表中选中“用户定义的按钮”,拖动到绘图工具栏下方,出现一个空白的工具栏按钮。单击空白的工具栏按钮,弹出“自定义”对话框的“按钮特性”选项卡,在“名称”输入框中,键入杆号,在“说明”输入框中,键入插入杆号。在“与此关联的宏”输入框中,键入“^C^C-VBARUN insertgh.dvb!ThisDrawing.insertgh”。如果有兴趣,可以为按钮做个图标。单击“编辑按钮”,打开“按钮编辑器”对话框,用画笔画一个图标,本例本人画了一个如“#”号的图标,单击“保存按钮”,然后单击“关闭”按钮。在“按钮特性”选项卡中,单击“应用”按钮,这时图标图案就出现在自己建立的工具栏中。这时你编的按钮就可以应用了。<o:p></o:p></P>

yuansong 发表于 2005-11-14 18:47:00

<P>用是可以用了,可出现的确认运行对话框太烦人,可以去除么?</P>
<P>&nbsp;</P>
页: [1]
查看完整版本: 怎么自动激活宏??