VBA IsObject Function

VBA IsObject Function in Excel

VBA IsObject function in Excel is categorizes as an Information function in VBA. It is a built-in function in MS Office Excel VBA. This function checks specific variable is an object or not. It has one input(Expression) parameter. VBA IsObject function returns a Boolean value either True or False.

The IsObject function can be use only in VBA. We can’t use this function as a worksheet function. This function can be use in either procedure or function in a VBA editor window in Excel. We can use this VBA IsObject function any number of times in any number of procedures or functions. In the following section we learn what is the syntax and parameters of the IsObject function, where we can use this VBA IsObject function and real-time examples.

Syntax of VBA IsObject Function

The syntax of the VBA IsObject function is

IsObject(Expression)

Note: The VBA IsObject function returns a Boolean value.

Parameters or Arguments

The IsObject function has one input parameter or argument.
Where
Expression: It is a required parameter. The argument an Expression that you want to evaluate.

Where we can apply or use VBA IsObject Function?

We can use this VBA IsObject function in MS Office 365, MS Excel 2016, MS Excel 2013, 2011, Excel 2010, Excel 2007, Excel 2003, Excel 2016 for Mac, Excel 2011 for Mac, Excel Online, Excel for iPhone, Excel for iPad, Excel for Android tablets and Excel for Android Mobiles.

Example 1: Check specific expression(undeclared variable) is object or not

Here is a simple example of the VBA IsObject function. This below example checks the specific undeclared variable is an object on not. The output of below macro is False.

'Check specific expression is object or not
Sub VBA_IsObject_Function_Ex1()
    
    'Variable declaration
    Dim iExpression As Integer
    Dim sOutput As Boolean
      
    sOutput = IsObject(iExpression)
   
    'Display output message
    MsgBox "The expression is object or not : " & sOutput, vbInformation, "VBA IsObject Function"
    
End Sub

Output: Here is the screen shot of the first example output.
VBA IsObject Function

Example 2: Check specific expression(declared variable) is object or not

Here is another example of the VBA IsObject function. This below example checks the specific declared variable is an object on not. The output of below macro is TRUE.

'Check specific expression is object or not
Sub VBA_IsObject_Function_Ex2()
    
    'Variable declaration
    Dim iExpression As Object
    Dim sOutput As Boolean
      
    sOutput = IsObject(iExpression)
   
    'Display output message
    MsgBox "The expression is object or not : " & sOutput, vbInformation, "VBA IsObject Function"
    
End Sub

Output: Here is the screen shot of the second example output.
VBA IsObject Function

Example 3: Check specific expression(variable set to an object) is object or not

Here is a simple example of the VBA IsObject function. This below example checks the specific variable set to an object is an object on not. The output of below macro returns False.

'Check specific expression is object or not
Sub VBA_IsObject_Function_Ex3()
    
    'Variable declaration
    Dim iExpression As Worksheet
    Dim sOutput As Boolean
    
    Set iExpression = Sheets("Sheet1")
      
    sOutput = IsObject(iExpression)
   
    'Display output message
    MsgBox "The expression is object or not : " & sOutput, vbInformation, "VBA IsObject Function"
    
End Sub

Output:Here is the screen shot of the third example output.
VBA IsObject Function

Example 4: Check specific expression is object(variable set to Nothing) or not

Here is a simple example of the VBA IsObject function. This below example checks the specific variable is an object on not. The output of below macro is False.


'Check specific expression is object or not
Sub VBA_IsObject_Function_Ex4()
    
    'Variable declaration
    Dim iExpression
    Dim sOutput As Boolean
    
    Set iExpression = Nothing
      
    sOutput = IsObject(iExpression)
   
    'Display output message
    MsgBox "The expression is object or not : " & sOutput, vbInformation, "VBA IsObject Function"
    
End Sub

Output: Here is the screen shot of the fourth example output.
VBA IsObject Function

Instructions to Run VBA Macro Code or Procedure:

You can refer the following link for the step by step instructions.

Instructions to run VBA Macro Code

Other Useful Resources:

Click on the following links of the useful resources. These helps to learn and gain more knowledge.

VBA Tutorial VBA Functions List VBA Arrays in Excel Blog

VBA Editor Keyboard Shortcut Keys List VBA Interview Questions & Answers

Leave a Reply