Constants

A constant is a meaningful name that takes the place of a value that does not change.
You should always use constants in place of hard coded values or strings.
Constants must be declared at the very top and cannot be declared below any properties, subroutines or functions.
Unlike variables, constants cannot be inadvertently changed at run-time.
You cannot use any variables, user defined function or any built-in functions in your declarations.
You should always declare your constants with specific data types (never with a Variant data type).
All public constants and variables should be in capitals except for the data type prefix


Constant Scope

The default scope for module level constants is Private.
Constants have scope and this scope is identical to that defined for variables.
This constant can only be used in the module that it is declared.

This constant can be used in any of the modules in the whole project.

For more details on the scope of variables, please refer to the Variables > Lifetime and Scope page.


Expressions

A constant can be defined using other, already declared constants.


Types of Constants

The VBA Language has several types of constants.
Literal constants A specific value such as a number, date or text string that cannot change.
Symbolic constants - A literal constant that is represented by a name.
Enumerations - A grouping of symbolic constants into categories.
Built-in constants - These are typically in the form of enumerations.
If you do not declare the data type of the constant then the most appropriate data type for the expression is used ??
In class modules constants can only be Private and their visibility cannot be changed to Public.


Literal Constants

A literal constant is a specific value such as number, date or text string that does not change.


Numbers

Numerical constants.


Dates

Date constants are enclosed between two hash signs #01/07/2014#.
You can but be aware that these dates ignore the regional settings and are always interpreted in US date format (mm/dd/yyyy).


Strings

String constants are enclosed between double speech marks.
To include a double speech mark inside a text string you need to prefix it with another double speech mark.


Symbolic Constants

This is also sometimes referred to as just a constant.
To define or declare a symbolic constant use the keyword Const.
Note that string constants are enclosed in double quotes "string".

In this case every instance of the variable sFOLDERPATH is replaced with the string "C:\Temp\".
sFOLDERPATH is a constant since it never changes but it is not a literal constant since it is not used anywhere.
The advantage of using symbolic constants is that if you decide to change the value at a later date you only need to change the definition of the variable sFOLDERPATH rather than searching and replacing all occurrences of the old string.


Built-in Constants

Also known as Intrinsic Constants.
In addition to literal and symbolic constants VBA also has a huge range of built-in constants.
Any built-in constants are examples of symbolic constants and generally start with the characters vb.

You should try and use the built-in constants rather than the values they represent because the value may change in future versions of VBA.
The constants are also more intuitive and easier to change at a later date, eg vbNewLine = Chr$(13).


Complete List

For a complete list of all the VBA constants refer to the Enumerations > VBA Constants page.


Remember

If you attempt to change the value of a constant you will receive an error.
The default scope for constants is Private.


© 2026 Better Solutions Limited. All Rights Reserved. © 2026 Better Solutions Limited TopPrevNext