Skip to content

RD should inspect for potential Worksheet_Change event re-entry. #4589

Open
@comintern

Description

@comintern

This might seem like an oddly specific inspection, but I'm finding myself dropping comments like this one on SO with increasing frequency:

You're getting into an infinite loop because you're changing the worksheet from inside the Change event. Use Application.EnableEvents = false before you make changes, then set it back to True when you're done.

The code below will lock up Excel the first time it executes:

Private Sub Worksheet_Change(ByVal Target As Range)
    Target.Value = "Foo"
End Sub

Obviously this is a contrived example (and an inspection would need some code path analysis), but RD should be able to tell if a Range.Value unambiguously is on the same worksheet and is not wrapped in a non-deterministic Application.EnableEvents = True and Application.EnableEvents = False call pair. The only instance that might be trickier is if there is a custom re-entry flag.

Metadata

Metadata

Assignees

No one assigned

    Labels

    code-path-analysisInvolves simulating execution paths / interpreting the user code ..to an extent.difficulty-04-quackheadDare?enhancementFeature requests, or enhancements to existing features. Ideas. Anything within the project's scope.feature-inspectionsup-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