下面的代码是 Excel 的 VBA。我使用的是 Excel 2007 附带的 Visual Basic 编辑器。
Dim counter As Integer
counter = 1
While counter < 20
counter = counter + 1
end while '<- the compiler is complaining about this statement
代码无法编译。在代码上方我只有声明。根据MSDN这应该有效,但事实并非如此。发生了什么?
最佳答案
While
构造不是用 End While
终止的,而是用 Wend
终止的。
While counter < 20
counter = counter + 1
Wend
请注意,此信息可以在文档中轻松获得;只需按F1即可。 page you link to处理 Visual Basic .NET,而不是 VBA。虽然(没有双关语)VBA 和 VB.NET 之间的语法存在一定程度的重叠,但不能仅仅假设其中一个的文档可以直接应用于另一个。
另外在 VBA 帮助文件中:
Tip The
Do...Loop
statement provides a more structured and flexible way to perform looping.
关于vba - "While .. End While"在 VBA 中不起作用?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9733699/