VBA IsObject Function

VBA IsObject Function

Objective of VBA IsObject Function

VBA IsObject function is categorized as an Information function in VBA. It is a built-in function in MS Office Excel VBA. This function checks specified variable is an object or not. It has one input(Expression) parameter. It has one parameter. It returns a Boolean value (True or False). The IsObject function can be used only in VBA. We can’t use this function as a worksheet function. This function can be used 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)

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 specified expression(undeclared variable) is object or not

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

'Check specified 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 specified expression(declared variable) is object or not

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

'Check specified 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 specified 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 specified variable set to an object is an object on not. The output of below macro returns False.

'Check specified 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 specified expression is object(variable set to Nothing) or not

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


'Check specified 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 use Macro Codes

Here are the step by step instructions to use the VBA IsObject function in Excel VBA.

  • Open an Excel workbook.
  • Press Alt+F11 to open VBA Editor window.
  • Go to Insert menu and click on module from the available options.
  • Copy above specified macros to the VBA editor.
  • Select any procedure from above codes and click on ‘Run’ command or use Keyboard shortcut ‘F5’.

List of VBA Functions:

Please click on below link to go back to see all List of VBA Functions.

List of VBA Functions

Leave a Comment

Your email address will not be published. Required fields are marked *