Skip to content

VBA231 — Const initialiser references a non-constant

Severity: 🔴 error Category: const_expression Phase: 2.5

Description

Const initialisers cannot reference variables — only literals, other constants, or enum members.

Failing example

Dim runtimeValue As Long
Const X As Long = runtimeValue

Compliant example

Const A As Long = 5
Const X As Long = A + 1

How to fix

Use a literal or another Const / Enum member as the initialiser.


Source: src/rules.py — entry VBA231.