Skip to content

VBA181 — Statement invalid inside Type block

Severity: 🔴 error Category: placement Phase: 3.7

Description

A Type … End Type block may only contain field declarations (Name [(dims)] As Type). Executable statements or Dim/Sub/… declarations inside it are illegal.

Failing example

Type T
    x As Long
    Sub Foo()
End Type

Compliant example

Type T
    x As Long
    y As String
End Type

How to fix

Move the statement outside the Type; keep only Name As Type fields inside.


Source: src/rules.py — entry VBA181.