Microsoft Office 2000/Visual Basic Programmer's Guide   

Calculating String Length

Often you need to know the length of a string in order to parse its contents. You can use the Len function to calculate the length of a string:

Dim lngLen As Long
lngLen = Len(strText)

When VBA stores a string in memory, it always stores the length of the string in a long integer at the beginning of the string. The Len function retrieves this value and is therefore quite fast.

The Len function is useful when you need to determine whether a string is a zero-length string (""). Rather than comparing the string in question to a zero-length string to determine whether they're equivalent, you can simply check whether the length of the string is equal to 0. For example:

If Len(strText) > 0 Then
   ' Perform some operation here.
End If