Skip to content

VBA360 — Module-only declaration inside a procedure body

Severity: 🔴 error Category: placement Phase: 3.5

Description

Type, Enum, Declare, Option, Implements and the DefInt/DefStr/… family are only legal at module scope. VBE refuses to compile a Sub/Function/Property that contains one of these declarations.

Failing example

Sub S()
    Type Point
        x As Long
        y As Long
    End Type
End Sub

Compliant example

Type Point
    x As Long
    y As Long
End Type

Sub S()
    Dim p As Point
End Sub

How to fix

Move the declaration outside any procedure, between the module attributes and the first Sub/Function.


Source: src/rules.py — entry VBA360.