![]() |
Microsoft Office Development and Consultancy |
| Home | | | Excel | | | VBA | | | C# | | | Finance | | | Tools | | | Newsletter | | | Feedback | | | Contact |
| VBA > Syntax > Enumerations | < Previous | Next > |
What is an Enumeration ? |
An enumeration is a distinct value which provides an alternative to using a constant. | ||
Every enumeration has an underlying type which can be any integral type: Integer, Short, Long etc | ||
Enumeration are typically in groups and provide a way of categorising your symbolic constants into a defined structure. | ||
A list of built-in enumerations can be seen in the object browser |
![]() |
Built-in Enumerations |
There are a huge number of built-in enumerations that are used to categorise all the built-in constants. | ||
For a full list of all these enumerations please refer to the dedicated Enumerations > Dedicated Enumerations Section. | ||
It is often a lot easier to remember the symbolic constant names rather than the actual numeric values. | ||
Using enumerations has the added benefit of enablying the Auto List Members feature to provide help. | ||
A good example of a built-in enumeration is related to the MsgBox function. |
|
Creating Enumerations |
It is possibe to create your own. | ||
Beware using floating point values with Enum. All constant values are treated as long integers rounded to the largest integer. | ||
The default type is Integer if omitted. |
|
If you don't specify any numerical values the enumeration will start at 0 and each subsequent value will incrememt by 1. |
|
|
Displaying the Enumeration Label |
Displaying the Enumeration Value |
When you want to display the value of an enumerated constant rather than its name you must cast the constant to its underlying type | ||
For example: |
|
|
Case Sensitive |
you can declare enumerations in mixed case but while using them in your subroutines you type them in lowercase it will change the original declaration to lowercase |
Things to Remember |
When you are referring to named ranges in your code never use the Range abbreviation [MyNamedRange]. | |||
Always fully qualify your enumerations. | |||
Always prefix your enumeration values with a "en" prefix so they are not accidentally confused with named ranges. | |||
These are not available in Office 97 and were only introduced in Office 2000. |
| © 2013 Better Solutions Limited. All Rights Reserved. | < Previous | Top | Next > | 02-Jan-2013 |