Illegal on declarations in this scope: <keyword>

The following conditions could have caused this error:

  • You used the keyword Dim, Public, Private, or Static when defining a member variable in a Type statement. For example:
    Type MyType
       Public X As Integer          ' Illegal: Public keyword is not allowed here.
    End Type

    Remove the Dim, Public, Private, or Static keyword.

  • You used the Dim keyword when defining a member variable in a Class statement. For example:
    Class MyClass
       Dim X As Integer             ' Illegal: Dim keyword is not allowed here.
    End Class

    Remove the Dim keyword.