Inspection Details

ShadowedDeclaration


Summary
Identifies identifiers that hide/"shadow" other identifiers otherwise accessible in that scope.
Reasoning
Global namespace contains a number of perfectly legal identifier names that user code can use. But using these names in user code effectively "hides" the global ones. In general, avoid shadowing global-scope identifiers if possible.
The following code example(s) would trigger this inspection:

Private MsgBox As String ' hides the global-scope VBA.Interaction.MsgBox function in this module.
Public Sub DoSomething()
    MsgBox = "Test" ' refers to the module variable in scope.
    VBA.Interaction.MsgBox MsgBox ' global function now needs to be fully qualified to be accessed.
End Sub

The following code example(s) would not trigger this inspection:

Private message As String
Public Sub DoSomething()
    message = "Test"
    MsgBox message ' VBA.Interaction module qualifier is optional.
End Sub


Back to List