xiaogui03 发表于 2008-4-21 11:33:00

vba如何终止执行

<p>sub A()中调用的函数function B() <br/>function B()内出现错误,捕获之后我用msgbox()提示,想在确认后停止整个sub A()的运行,请问各位高人该如何实现?</p><p>sub A()<br/>……<br/>a=function B()<br/>……<br/>end&nbsp;sub&nbsp;</p><p>function B()<br/>……<br/>on error goto myerror<br/>……<br/>myerror:<br/>&nbsp;msgbox("输入错误,请检查")<br/>???????<br/>end function</p><p>“???????”部分不知如何实现</p>

cctv2cctv 发表于 2008-4-21 13:27:00

<div style="WIDTH: 728px; HEIGHT: 90px;"><script type="text/javascript"></script><script src="http://pagead2.googlesyndication.com/pagead/show_ads.js" type="text/javascript"></script><iframe name="google_ads_frame" marginwidth="0" marginheight="0" src="http://pagead2.googlesyndication.com/pagead/ads?client=ca-pub-7471407183047897&amp;dt=1208755141500&amp;lmt=1208755141&amp;prev_fmts=728x90_as%2C120x90_0ads_al_s&amp;format=728x90_as&amp;output=html&amp;correlator=1208755139265&amp;channel=9653521252&amp;pv_ch=9653521252%2B&amp;url=http%3A%2F%2Fwww.mjtd.com%2FBBS%2Fdispbbs.asp%3FboardID%3D4%26ID%3D67208%26page%3D1&amp;color_bg=FFFFFF&amp;color_text=000000&amp;color_link=0000FF&amp;color_url=008000&amp;color_border=C3D9FF&amp;ad_type=text_image&amp;ref=http%3A%2F%2Fwww.mjtd.com%2FBBS%2Flogin.asp&amp;frm=0&amp;cc=100&amp;ga_vid=1255804713.1208754695&amp;ga_sid=1208754695&amp;ga_hid=1388894835&amp;ga_fc=true&amp;flash=0&amp;u_h=768&amp;u_w=1024&amp;u_ah=738&amp;u_aw=1024&amp;u_cd=32&amp;u_tz=480&amp;u_his=4&amp;u_java=true" frameborder="0" width="728" scrolling="no" height="90" allowtransparency="allowtransparency"></iframe></div><p>sub A()中调用的函数function B() <br/>function B()内出现错误,捕获之后我用msgbox()提示,想在确认后停止整个sub A()的运行,请问各位高人该如何实现?</p><p>sub A()<br/>……<br/>a=function B()<br/>s:if m=0 then exit sub;end&nbsp;sub&nbsp;</p><p>function B()<br/>……<br/>on error goto myerror<br/>……<br/>myerror:<br/>&nbsp;m=msgbox("输入错误,请检查")<br/>if m=0; 即点击了OK</p><p>goto s<br/>end function</p><p></p><p>或者function B()有返回值的话</p><p>sub A()<br/><br/>……<br/>a=function B()<br/>if a=0 then exit sub</p><p>function B()<br/>……<br/>on error goto myerror<br/>……<br/>myerror:<br/>&nbsp;m=msgbox("输入错误,请检查")<br/>end function;让funciton B()返回0</p><p></p><p>大概就是这么个意思代码,自己再改改吧</p>

xiaogui03 发表于 2008-4-21 15:07:00

<p>好方法!谢过啦!</p><p>也就是说VBA里面是没有停止运行的语句啦?不知是不是这样?</p>
页: [1]
查看完整版本: vba如何终止执行