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 301 forks source link

False Positive "Set Assignment with Incompatible Object Type" with CodeName of Excel.Worksheet #5286

Closed ChrisBrackett closed 4 years ago

ChrisBrackett commented 5 years ago

Rubberduck version information

Version 2.4.1.5196
OS: Microsoft Windows NT 10.0.17763.0, x64
Host Product: Microsoft Office 2016 x64
Host Version: 16.0.4912.1000
Host Executable: EXCEL.EXE

Description RD inspection flags "Set assignment with incompatible object type" error when setting an Excel.Worksheet variable with an Excel.Worksheet codename. This wasn't always flagged by RD in the past though I'm not sure when it started.

The code below looks clean to me. Is this intentionally flagged?

To Reproduce Steps to reproduce the behavior:

  1. With a new Excel file, insert a standard code module and add this code:
Private Sub test()
    Dim ws As Excel.Worksheet
    Set ws = Sheet2
    Debug.Print TypeName$(Sheet2)
End Sub
  1. Refresh RD and see the inspection result.
retailcoder commented 5 years ago

This is a long-standing resolver issue that I wish we could fix before releasing 2.5.0, now that we have what it takes to fix it (namely, identifying the base class for document modules, via the TypeLib API).

Until then, RD doesn't know that Sheet1 is a Worksheet, or that ThisWorkbook is a Workbook.

ChrisBrackett commented 5 years ago

Endless possibilities...Does that also cover the possibility that document module Chart1 could be a chart object?

retailcoder commented 5 years ago

Yes