Rubberduck: False Positive "Set Assignment with Incompatible Object Type" with CodeName of Excel.Worksheet

Created on 14 Nov 2019  路  3Comments  路  Source: rubberduck-vba/Rubberduck

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.
bug resolver

All 3 comments

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.

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

Yes

Was this page helpful?
0 / 5 - 0 ratings