Type Checking


VARTYPE Function

You can use the VARTYPE function to return the number indicating the data type of a variable.

Dim dbValue As Double 
dbValue = 123

If (VarType(dbValue) = VBA.vbVarType.vbDouble) Then
End If

TYPENAME Function

You can use the TYPENAME function to return the data type of a variable as a string.

Dim bBoolean As Boolean 
bBoolean = False

If (TypeName(bBoolean) = "Boolean") Then
End If

TYPEOF Operator

You can use the TYPEOF operator to return the object data type.
This can only be used with object data types.
This cannot be used with value data types.

Dim oFileSystem As Scripting.FileSystemObject 
Set oFileSystem = New Scripting.FileSystemObject

If (TypeOf oFileSystem Is Scripting.FileSystemObject) Then
End If

© 2024 Better Solutions Limited. All Rights Reserved. © 2024 Better Solutions Limited TopPrevNext