IsObject function
Returns a Boolean value indicating whether an identifier represents an object variable.
Syntax
IsObject(identifier)
The required identifier argument is a variable name.
Remarks
IsObject is useful only in determining whether a Variant is of VarType vbObject. This could occur if the Variant actually references (or once referenced) an object, or if it contains Nothing.
IsObject returns True if identifier is a variable declared with Object type or any valid class type, or if identifier is a Variant of VarType vbObject, or a user-defined object; otherwise, it returns False.
IsObject returns True even if the variable has been set to Nothing. Use error trapping to be sure that an object reference is valid.
Note
This function is useful in error handling sections of the code where you are not sure whether an object was instantiated before the error occurred, and for example, you want to close it.
Example
This example uses the IsObject function to determine if an identifier represents an object variable. MyObject and YourObject are object variables of the same type. They are generic names used for illustration purposes only.
Dim MyInt As Integer ' Declare variables.
Dim YourObject, MyCheck ' Note: Default variable type is Variant.
Dim MyObject As Object
Set YourObject = MyObject ' Assign an object reference.
MyCheck = IsObject(YourObject) ' Returns True.
MyCheck = IsObject(MyInt) ' Returns False.
MyCheck = IsObject(Nothing) ' Returns True.
MyCheck = IsObject(Empty) ' Returns False.
MyCheck = IsObject(Null) ' Returns False.
See also
Support and feedback
Have questions or feedback about Office VBA or this documentation? Please see Office VBA support and feedback for guidance about the ways you can receive support and provide feedback.
피드백
https://aka.ms/ContentUserFeedback
출시 예정: 2024년 내내 콘텐츠에 대한 피드백 메커니즘으로 GitHub 문제를 단계적으로 폐지하고 이를 새로운 피드백 시스템으로 바꿀 예정입니다. 자세한 내용은 다음을 참조하세요.다음에 대한 사용자 의견 제출 및 보기