Skip to content

OptionExplicitInspection

Max Dörner edited this page Jun 2, 2019 · 3 revisions

Description: Option Explicit is not specified

Type: CodeInspectionType.CodeQualityIssues

Default severity: CodeInspectionSeverity.Warning

This inspection finds modules that do not specify Option Explicit

Example:

This module does not specify Option Explicit

Option Private Module

Public Sub DoSomething(foo As Integer)
    bar = foo
End Sub

VBA will happily compile and run this code, even though bar isn't declared anywhere. With Option Explicit specified, one gets a useful compile-time error about the undeclared variable.


QuickFixes

QuickFix: Specify Option Explicit

Option Explicit
Option Private Module

Public Sub DoSomething(foo As Integer)
    bar = foo ' compile error
End Sub

This quickfix introduces an Option Explicit instruction at the top of the faulty code module.

Clone this wiki locally