5.2.4.1.1 Class Accessibility and Instancing

The ability to reference a class by its name is determined by the accessibility of its class definition. This accessibility is distinct from the ability to use the class name to create new instances of the class.

The accessibility and instancing characteristics of a class are determined by the module attributes on its class module declaration, as defined by the following table:

Instancing Mode

Meaning

Attribute Values

Private (default)

The class is accessible only within the enclosing project.

 

Instances of the class can only be created by modules contained within the project that defines the class.

VB_Exposed=False VB_Creatable=False

Public Not Creatable

The class is accessible within the enclosing project and within projects that reference the enclosing project.

 

Instances of the class can only be created by modules within the enclosing project. Modules in other projects can reference the class name as a declared type but can’t instantiate the class using new or the CreateObject function.

VB_Exposed=True VB_Creatable=False

Public Creatable

The class is accessible within the enclosing project and within projects that reference the enclosing project.

 

Any module that can access the class can create instances of it.

VB_Exposed=True VB_Creatable=True

 

An implementation MAY define additional instancing modes that apply to classes defined by library projects.