Inspection Details


Locates unqualified Workbook.Worksheets/Sheets/Names member calls that implicitly refer to ActiveWorkbook.
Implicit references to the active workbook rarely mean to be working with *whatever workbook is currently active*. By explicitly qualifying these member calls with a specific Workbook object, the assumptions are removed, the code is more robust, and will be less likely to throw run-time error 1004 or produce unexpected results when the active workbook isn't the expected one.
This inspection will only run if the following libraries referenced:
The following code example(s) would trigger this inspection:

Private Sub Example()
    Dim summarySheet As Worksheet
    Set summarySheet = Worksheets("Summary") ' unqualified Worksheets is implicitly querying the active workbook's Worksheets collection.
End Sub

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

Private Sub Example(ByVal book As Workbook)
    Dim summarySheet As Worksheet
    Set summarySheet = book.Worksheets("Summary")
End Sub

Back to List