日记首页
|
列表
|
添加日记
|
管理登陆
标题:vba跳转,vba跳过代码
<div class="dpu8C _2kCxD " style="max-width: 100%; overflow-x: visible; line-height: 30px;"><h3 data-from-paste="1" data-diagnose-id="5f85bfb94237575699ac5ed7cf86a71c" style="margin: 0px; padding: 0px; overflow-y: auto; max-width: 100%;"><font color="#222222" face="arial" size="2" style="font-weight: normal;">GoTo、On…GoTo语句</font></h3><h3 data-from-paste="1" data-diagnose-id="5f85bfb94237575699ac5ed7cf86a71c" style="margin: 0px; padding: 0px; overflow-y: auto; max-width: 100%;"><font color="#222222" face="arial" size="2" style="font-weight: normal;">1.GoTo语句</font></h3><h3 data-from-paste="1" data-diagnose-id="5f85bfb94237575699ac5ed7cf86a71c" style="margin: 0px; padding: 0px; overflow-y: auto; max-width: 100%;"><font color="#222222" face="arial" size="2" style="font-weight: normal;">无条件地跳转到程序的某个标记,此标记可以利用任何字符组合,以字母开头,以冒号结尾。</font></h3><h3 data-from-paste="1" data-diagnose-id="5f85bfb94237575699ac5ed7cf86a71c" style="margin: 0px; padding: 0px; overflow-y: auto; max-width: 100%;"><font color="#222222" face="arial" size="2" style="font-weight: normal;">2.On…GoTo语句</font></h3><h3 data-from-paste="1" data-diagnose-id="5f85bfb94237575699ac5ed7cf86a71c" style="margin: 0px; padding: 0px; overflow-y: auto; max-width: 100%;"><font color="#222222" face="arial" size="2" style="font-weight: normal;">如果希望根据表达式的结果而决定跳转到某个标记处,需要利用On…GoTo语句,语句法如下:</font></h3><h3 data-from-paste="1" data-diagnose-id="5f85bfb94237575699ac5ed7cf86a71c" style="margin: 0px; padding: 0px; overflow-y: auto; max-width: 100%;"><font color="#222222" face="arial" size="2" style="font-weight: normal;">On expression GoSub destinationlist</font></h3><h3 data-from-paste="1" data-diagnose-id="5f85bfb94237575699ac5ed7cf86a71c" style="margin: 0px; padding: 0px; overflow-y: auto; max-width: 100%;"><font color="#222222" face="arial" size="2" style="font-weight: normal;">On expression GoTo destinationlist</font></h3></div><hr style="font-family: Arial; font-size: 10.5pt;"><p style="font-family: Arial; font-size: 10.5pt;"><span style="font-family: Arial; font-size: 14px;">首选:</span></p><p style="font-family: Arial; font-size: 10.5pt;"><span style="font-family: Arial; font-size: 14px;">GoTo</span><span style="font-family: Arial; font-size: 14px;"> </span><font face="Arial"><span style="font-size: 14px;">Skip</span></font></p><p style="font-family: Arial; font-size: 10.5pt;"><strong style="font-family: Arial; font-size: 14px;"> </strong><span style="font-family: Arial; font-size: 14px;">................ ' 不会被执行</span></p><p style="font-family: Arial; font-size: 10.5pt;">Skip</p><hr style="font-family: Arial; font-size: 10.5pt;"><p style="font-family: Arial; font-size: 10.5pt;">GoTo LastLine<br><strong> </strong>................ ' 不会被执行<br> <br>LastLine: ' 接GoTo LastLine 完成</p><p style="font-family: Arial; font-size: 10.5pt;"></p><hr style="font-family: Arial; font-size: 10.5pt;"><p style="font-family: Arial; font-size: 10.5pt;"></p><p style="font-family: Arial; font-size: 10.5pt;">示例:</p><p style="font-family: Arial; font-size: 10.5pt;">Sub GotoStatementDemo()<br> Dim Number, MyString<br> Number = 1 ' 设置变量初始值。<br> ' 判断 Number 的值以决定要完成那一个程序区段(以“程序标签”来表式)。<br> If Number = 1 Then GoTo Line1 Else GoTo Line2<br> <br> Line1:<br> MyString = "Number equals 1"<br> GoTo LastLine ' 完成最后一行。<br>Line2:<br> ' 下列的语句根本不会被完成。<br> MyString = "Number equals 2"<br> LastLine: ' 接GoTo LastLine 完成<br> Debug.Print MyString ' 将“"Number equals 1"”显示在“立即”窗口。<br>End Sub</p>