rubberduck-vba / Rubberduck

Every programmer needs a rubberduck. COM add-in for the VBA & VB6 IDE (VBE).
https://rubberduckvba.com
GNU General Public License v3.0
1.92k stars 302 forks source link

Inspection for Use of New keyword for non-creatable class #2384

Open ThunderFrame opened 7 years ago

ThunderFrame commented 7 years ago

Some CoClasses don't have public constructors, so VBA can't New 'em up.

Set myWorkbook = New Workbook

With New Workbook
  Beep
End With

The quickfix would require knowing the factory method(s) and be host/TLB specific.

Set myWorkbook = Workbooks.Add

With Workbooks.Add
  Beep
End With
retailcoder commented 7 years ago

Given there's no compile error with Set foo = New Workbook, I like the inspection... but I don't think the quickfixes would be realistic, there's just too many edge cases. Even for a Workbook, the Workbooks collection could be owned by anotherApplication instance.. not to mention cases where the Excel object model is referenced from another host.

We could have an error-level inspection result for it, but there wouldn't be a quick-fix for it. (not even ignore once?)