mafan 发表于 2005-7-14 15:06:00

怎样才能在vba执行时退出vba程序,但不退出cad

<P>怎样才能在vba执行时退出vba程序,但不退出cad</P>
<P><BR>我现在做一个程序,想作一段错误处理,<BR>即出错时就退出vba程序,但不想退出cad</P>
<P>怎样才可以</P>

fanny_6 发表于 2005-7-14 15:21:00

<P>on error goto abc</P>
<P>在end前加&nbsp; abc:</P>
<P>不知道有没理解错你的意思</P>

mafan 发表于 2005-7-14 17:46:00

<P>sorry<BR>不是这个意思<BR>我是进行了很多层函数调用,其中在一个函数中出错,我想在<BR>那里直接退出vba程序,既中断程序,但不退出AutoCAD<BR><BR>不知道这样是否可能实现</P>

雪山飞狐_lzh 发表于 2005-7-14 17:58:00

<P>是退出当前子程还是宏?</P>
<P>不太懂你的意思</P>

mikewolf2k 发表于 2005-7-14 19:42:00

<P>2楼方法可行。</P>
<P>sub aa()</P>
<P>......</P>
<P>on error goto exitvba:</P>
<P>......</P>
<P>exit sub</P>
<P>exitvba:</P>
<P>end</P>
<P>end sub</P>

mafan 发表于 2005-7-15 14:07:00

<P>不好意思,本人表达的可能不是很清楚,请各位谅解</P>
<P><BR>我是想在当前子程序中直接退出vba的执行</P>

my_computer 发表于 2005-7-16 09:52:00

<P>支持 2 楼。</P>

yxh1202 发表于 2010-6-8 14:25:00

<p>看到这个问题我也在找答案,我的意思是VBA执行中按esc键就可以退出VBA程序但不退出CAD,怎么办</p>

wwswwswws 发表于 2010-6-26 21:06:00

<p>要使用API函数,检测键盘</p>
<p><font face="Verdana">Private Declare Function GetAsyncKeyState Lib "user32" (ByVal vKey As Long) As Integer</font></p>
<p><font face="Verdana">Private Const VK_ESCAPE = &amp;H1B</font></p>
<p>&nbsp;</p>
<p><font face="Verdana">Private Function CheckKey(lngKey As Long) As Boolean<br/>&nbsp;&nbsp; If GetAsyncKeyState(lngKey) Then<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; CheckKey = True<br/>&nbsp;&nbsp; Else<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; CheckKey = False<br/>&nbsp;&nbsp; End If<br/>End Function</font></p>
<p>&nbsp;</p>
<p>sub&nbsp; 你的程序</p>
<p>'進入这个程序,运行一次这个程序</p>
<p><font face="Verdana">GetAsyncKeyState VK_ESCAPE</font></p>
<p>do</p>
<p>...........</p>
<p>..........</p>
<p><font face="Verdana">If CheckKey(VK_ESCAPE) = True Then&nbsp;&nbsp;&nbsp;'检测是不是按下了ESC键</font></p>
<p><font face="Verdana">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;........<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Exit Sub<br/>&nbsp;&nbsp; End If</font></p>
<p>loop</p>
<p>.................</p>
<p>end sub</p>
<p>&nbsp;</p>
<p>希望能帮到你的忙</p>
页: [1]
查看完整版本: 怎样才能在vba执行时退出vba程序,但不退出cad