VBA: Conditional - Is Nothing

后端 未结 3 2105
半阙折子戏
半阙折子戏 2020-12-16 11:34

There is an If condition in a VBA application as seen below:

If Not My_Object Is Nothing Then
My_Object.Compute

When the code

3条回答
  •  渐次进展
    2020-12-16 12:19

    In my sample code, I was setting my object to nothing, and I couldn't get the "not" part of the if statement to work with the object. I tried if My_Object is not nothing and also if not My_Object is nothing. It may be just a syntax thing I can't figure out but I didn't have time to mess around, so I did a little workaround like this:

    if My_Object is Nothing Then
        'do nothing
    Else
        'Do something
    End if
    

提交回复
热议问题