Excel VBA IsObject Function

VBA IsObject Function: The IsObject function in VBA returns a Boolean value showing whether the specified variable represents an Object variable type or not.

Syntax

IsObject (Expression)

Parameter

Expression (required)- This parameter represents the variable that you want to check.

Return

This function returns a Boolean value True if the given expression represents an Object variant type else it returns False.

Example 1

Sub IsObject_Example1()
 Dim var As Object
 Dim is_Obj As Boolean
 Is_Obj = IsObject(var)
 ' The variable isObj will return True.
 MsgBox (is_Obj)
 End Sub 

Output

True

VBA IsObject Function

Example 2

Sub IsObject_Example2()
 Dim var
 Dim is_Obj As Boolean
 var = Range("A1")
 is_Obj = IsObject(var)
 ' The variable isObj will return False.
 MsgBox (is_Obj)
 End Sub 

Output

False

VBA IsObject Function

Example 3

Sub IsObject_Example3()
 Dim var
 Dim is_Obj As Boolean
 var = Range("A1")
 'setting variable var as an object type
 Set var = Nothing
 is_Obj = IsObject(var)
 ' The variable isObj will return True.
 MsgBox (is_Obj)
 End Sub 

Output

VBA IsObject Function