Is (operator)

Syntax object Is [object | Nothing]
Description Returns True if the two operands refer to the same object; returns False otherwise.
Comments This operator is used to determine whether two object variables refer to the same object. Both operands must be object variables of the same type (i.e., the same data object type or both of type Object ). The Nothing constant can be used to determine whether an object variable is uninitialized:
  If MyObject Is Nothing Then MsgBox "MyObject is uninitialized."
Uninitialized object variables reference no object.
Example This function inserts the date into a Microsoft Word document.
Sub InsertDate(ByVal WinWord As Object)
  If WinWord Is Nothing Then
    MsgBox "Object variant is not set."
  Else
    WinWord.Insert Date$
  End If
End Sub
Sub Main()
  Dim WinWord As Object
  On Error Resume Next
  WinWord = CreateObject("word.basic")
  InsertDate WinWord
End Sub
See Also Operator Precedence (topic); Like (operator).
Platform(s) All.
Notes When comparing OLE automation objects, the Is operator will only return True if the operands reference the same OLE automation object. This is different from data objects. For example, the following use of Is (using the object class called excel.application ) returns True :
  Dim a As Object
  Dim b As Object
  a = CreateObject("excel.application")
  b = a
  If a Is b Then Beep
The following use of Is will return False , even though the actual objects may be the same:
  Dim a As Object
  Dim b As Object
  a = CreateObject("excel.application")
  b = GetObject(,"excel.application")
  If a Is b Then Beep 
The Is operator may return False in the above case because, even though a and b reference the same object, they may be treated as different objects by OLE 2.0 (this is dependent on the OLE 2.0 server application).