在While...Wend
循環中,如果條件為True
,則會執行所有語句,直到遇到Wend
關鍵字。
如果條件為false
,則退出循環,然后控件跳轉到Wend
關鍵字后面的下一個語句。
語法
以下是VBA中While..Wend
循環的語法。
While condition(s) [statements 1] [statements 2] ... [statements n] Wend
流程圖
示例
參考以下示例代碼的實現 -
Private Sub Constant_demo_Click() Dim Counter : Counter = 10 While Counter < 15 ' Test value of Counter. Counter = Counter + 1 ' Increment Counter. msgbox "The Current Value of the Counter is : " & Counter Wend ' While loop exits if Counter Value becomes 15. End Sub
當上面的代碼被執行時,它會在消息框中打印以下內容。
The Current Value of the Counter is : 11 The Current Value of the Counter is : 12 The Current Value of the Counter is : 13 The Current Value of the Counter is : 14 The Current Value of the Counter is : 15