3

我在 VBA 中有一个通常返回数组的函数。如果没有要返回的内容,则返回一个空变量 ( b = empty)。我有一些代码可以循环遍历数组,但如果变量不是数组,则会出现错误。如何做出不会导致自身错误的 if 语句。我努力了

if not b = empty then
'do the loop
end if

但是当 b 是一个数组b = nullb = nothing会出错b(1,1) = ""

检查这个的最好方法是什么?

4

1 回答 1

6

要测试变量是否为空,请使用IsEmpty函数。

If IsEmpty(b) Then
    Debug.Print "b is Empty"
End If

要测试变量是否为数组,请使用VarType函数。

If VarType(b) And vbArray Then
    Debug.Print "b is an array"
End If
于 2012-10-23T09:59:21.920 回答