VBA 优先于`If Len(myString)= 0然后`而不是`If myString =“”然后`

示例

当检查字符串是否为零长度时,检查字符串的长度而不是将字符串与空字符串进行比较是一种更好的做法,并且效率更高。

Const myString As String = vbNullString

'Prefer this method when checking if myString is a zero-length string
If Len(myString) = 0 Then
   Debug.Print"myString is zero-length"
End If

'Avoid using this method when checking if myString is a zero-length string
If myString = vbNullString Then
   Debug.Print"myString is zero-length"
End If