Option Explicit Statement

指定必须使用 Dim 语句明确声明程序代码中的每个变量。

语法:

Option Explicit

参数:

警告图标

此语句必须位于模块中的可执行程序代码之前。


示例:

Option Explicit

Sub ExampleExplicit

Dim sVar As String

    sVar = "Las Vegas"

    For i% = 1 To 10 ' 将导致运行时错误

        Rem

    Next i%

End Sub