Inspection Details

ObjectVariableNotSet


Summary
Warns about assignments that appear to be assigning an object reference without the 'Set' keyword.
Reasoning
Omitting the 'Set' keyword will Let-coerce the right-hand side (RHS) of the assignment expression. If the RHS is an object variable, then the assignment is implicitly assigning to that object's default member, which may raise run-time error 91 at run-time.
The following code example(s) would trigger this inspection:

Public Sub DoSomething()
    Dim foo As Object
    foo = New Collection
    ' ...
End Sub

The following code example(s) would not trigger this inspection:

Public Sub DoSomething()
    Dim foo As Object
    Set foo = New Collection
    ' ...
End Sub


Back to List