Option Explicit
- Last UpdatedJul 18, 2023
- 1 minute read
Forces explicit declaration of all variables.
The optional Option Explicit statement if used, must be placed at the top of the VBA file. This causes a check of variable declarations at compile time. Setting this option is a good way to catch misspelling of variables in your code.
Syntax
Option Explicit
Related Functions
Example
Option Explicit
' various statements go here
' a compile error will occur with the following line
strMyVar = "This string assignment won't work"
'because strMyVar is not explicitly declared