Access Sheet Using Code Name Quick Fix

Modifies a Workbook.Worksheets or Workbook.Sheets call accessing a sheet of ThisWorkbook that exists at compile-time.

This quick-fix is available for the SheetAccessedUsingString inspection

Applicability

This quick-fix can be applied as a single operation at the following scopes:
  • Procedure
  • Module
  • Project

Examples

 This example depicts the state of module(s) before and after applying the quick-fix.

Before
Module1 (Any)
Public Sub DoSomething() Dim sheet As Worksheet Set sheet = ThisWorkbook.Sheets("Sheet1") End Sub
After
Module1 (Any)
Public Sub DoSomething() Dim sheet As Worksheet Set sheet = Sheet1 '<~ note: local variable becomes redundant End Sub

Rubberduck.CodeAnalysis.QuickFixes.Concrete.AccessSheetUsingCodeNameQuickFix.cs (Prerelease-v2.5.2.6174)