<< Click to Display Table of Contents >> Option Explicit (statement) |
Option Explicit
Causes the usage of undefined variables to be flagged as a syntax error.
By default, variables which are used without having been declared before with Dim or Static, are silently created (as Variant variables). This is convenient, but makes typos in variable names go unnoticed.
When using the Option Explicit statement, the use of unknown variable names causes an error message.
Example:
Option Explicit
Sub Main
Print y ' Error because y was not declared.
End Sub