Procedure Not Used

Locates procedures that are never invoked from user code.

Remarks

Not all unused procedures can/should be removed: ignore any inspection results for event handler procedures or annotate them with @EntryPoint. Members that are annotated with @EntryPoint (or @ExcelHotkey) are not flagged by this inspection, regardless of the presence or absence of user code references. Moreover, unused public members of exposed class modules will not be reported.

Reasoning

Unused procedures are dead code that should probably be removed. Note, a procedure may be effectively "not used" in code, but attached to some Shape object in the host document: in such cases the inspection result should be ignored.

Default severity

Warning

Inspection type

CodeQualityIssues

Examples

This example should trigger a result

Module1 (StandardModule)
Option Explicit Private Sub DoSomething() End Sub

This example should NOT trigger a result

Module1 (StandardModule)
Option Explicit '@Ignore ProcedureNotUsed Private Sub DoSomething() End Sub

This example should NOT trigger a result

Macros (StandardModule)
Option Explicit Public Sub DoSomething() 'a public procedure in a standard module may be a macro 'attached to a worksheet Shape or invoked by means other than user code. End Sub

This example should trigger a result

Class1 (ClassModule)
Option Explicit Public Sub DoSomething() End Sub Public Sub DoSomethingElse() End Sub
Module1 (StandardModule)
Option Explicit Public Sub ReferenceOneClass1Procedure() Dim target As Class1 Set target = new Class1 target.DoSomething End Sub

This example should NOT trigger a result

Class1 (ClassModule)
Option Explicit Public Sub DoSomething() End Sub Public Sub DoSomethingElse() End Sub
Module1 (StandardModule)
Option Explicit '@EntryPoint "Rounded Rectangle 1" Public Sub ReferenceAllClass1Procedures() Dim target As Class1 Set target = new Class1 target.DoSomething target.DoSomethingElse End Sub

Rubberduck.CodeAnalysis.Inspections.Concrete.ProcedureNotUsedInspection.cs (Prerelease-v2.5.9.6289)