Open ThunderFrame opened 6 years ago
Doesn't need much code path analysis: we just need to know that there's only a single reference that isn't an assignment, and the parent of that reference's context is a With
block. Covers the first case anyway; the last case would already pop a 'variable assigned but not referred to' inspection result; I think early/late binding is beyond the scope of that inspection though.
Note that a potential issue is that typing may get lost. We probably don't want that. Example:
Dim rs As DAO.Recordset
Set rs = Me.RecordsetClone 'This returns an object, cast to DAO.Recordset
With rs
...
End With
The inspection should not fire for those, IMO.
@bclothier, good point. Same would apply to:
With ThisWorkbook.Worksheets("Foo")
'....
End With
Given code like this, where a variable is declared and instantiated, but then never used beyond the with block.
The code could be more concisely written as:
Or better still, prompt the user to make the reference early-bound
But the object needn't be a created object, it could just be using the host's model: