Table of Contents

VBC09311 — User-defined type not defined

Severity: Error  ·  Family: VBC (static semantics / abstract syntax tree)  ·  Source metadata: VBCompileErrorInfo

The type of a variable, parameter, constant or result is a name that does not resolve to a type: a name nothing declares, or the name of a procedural module, which is not a type. The type of a field of a user-defined type, or of a constant declared in a procedure, raises it only when it binds a procedural module: a name that does not resolve is not checked there yet.

The term is VBA's: it stands for a type the workspace defines, which is not necessarily a Type declaration. MS-VBA reports the same error: User-defined type not defined.

This code is raised by DeclarationStaticSemanticsEvaluator, NewExpressionStaticSemantics, ImplementsSemantics.

How it is raised

Situation Example Resolution
A declaration names a type that is not defined. Dim w As Widget with no Widget class or type Define the type, add the reference, or correct the name.
A declaration qualifies a type with a library that the project does not reference. Dim ws As Excel.Worksheet, in a project with no reference to Excel Add the reference to the project. Code that uses a library is not valid in a project that does not reference it.
A declaration qualifies a type with a module that does not declare it, or declares it Private. Dim p As Shapes.TPoint, where Shapes declares no public TPoint Declare the type Public in that module, or correct the name.
A declaration names a procedural module, of the project or of a library, as a type. Dim s As Strings; Dim m As Module1; with Excel referenced, Dim c As Constants, which is the VBA library's module before it is Excel's Enum Name a type. A library's type that shares a module's name is named through its library (Excel.Constants).
New names something that is not a class. Set x = New Missing Name a class.
Implements names an interface that does not exist. Implements IMissing Name a class module of the project.

See also


⏮️ VBC09310 Type mismatch | ⏭️ VBC09312 Exit Do not within Do...Loop


ACCUEIL • HOME | ℹ️ BIENVENUE • WELCOME | 🧩 BÂTISSONS • BUILD | RD-VBAL | SDK | 🌐 rubberduckvba.ca