Skip to content

Operation is not supported in Excel UDF #3881

Open
@retailcoder

Description

@retailcoder

Let's make an Excel-specific inspection that flags instructions that can't be used in a UDF, causing undesired behavior. Inspection should ignore modules with Option Private Module set, and only look at standard/procedural modules.

  • ActiveCell calls that mean to work against the cell being calculated, should be replaced with Application.Caller.
  • Application.Calculation, Application.EnableEvents, Application.ScreenUpdating assignments, are illegal.
  • Range.Activate calls can't be removed without breaking the code, but need to be flagged as illegal anyway.
  • Range.Insert, Range.Delete, Range.BorderAround, assignment to any FormatCondition member (or any FormatConditions method call), assignments to any Border members, or any Font members, are illegal.
  • Assignments to Range.Value, Range.Value2, and Range.[_Default] (or to any Range property for that matter) are illegal and should be removed.
  • Names.Add calls are illegal and should be removed.
  • Assignments to Sheet.Name (Worksheet.Name), Sheets.Add (Worksheets.Add), Sheet.Delete, Sheets.Delete (Worksheet.Delete, Worksheets.Delete), Sheet.Copy (Worksheet.Copy), are all illegal too.
  • Charts method calls, and Chart property assignments and method calls are illegal.
  • PivotTables method calls, and PivotTable property assignments and method calls are illegal.
  • ListObject , ListRow and ListColumn method calls and property assignments are illegal.

Probably forgetting a number of others...

Operation is not supported in a User-Defined Function
A public function in a standard procedural module is exposed to Excel worksheets as a UDF. These functions can produce invalid results when invoked from a worksheet. If the function isn't intended to be exposed as a UDF, consider specifying 'Option Private Module'.

One quick-fix could be to move the function to another standard/procedural module with Option Private Module specified; another option could be to specify Option Private Module at the top of the module. Another quick-fix could be to outright remove the illegal statement. Support for "Fix in procedure" is a must here.

Metadata

Metadata

Assignees

No one assigned

    Labels

    code-path-analysisInvolves simulating execution paths / interpreting the user code ..to an extent.difficulty-03-duckInvolves more challenging problems and/or developing within and revising the internals APIenhancementFeature requests, or enhancements to existing features. Ideas. Anything within the project's scope.feature-inspectionslibrary-specificup-for-grabsUse this label in conjunction with a difficulty level label, e.g. difficulty-02-ducky

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions