3.10. Intrinsic Constants

In addition to allowing you to define your own constants using the Const keyword, VBA includes a number of built-in or intrinsic constants whose values are predefined by VBA. Along with saving you from having to define these values as constants, the major advantage of using intrinsic constants is that they enhance the readability of your code. So, for instance, instead of having to write code like this:

If myObject.ForeColor = &hFFFF Then

you can write:

If myObject.ForeColor = vbYellow Then

Intrinsic constants are now available for most operations. The best place to find information about the available intrinsic constants is in the VB object browser, which you can open by selecting Object Browser from the View menu or by pressing F2. In many cases, though, a list of available constants for a particular operation will pop up as you are entering the code. Appendix B also lists constants available in VB and VBA.

Get VB & VBA in a Nutshell: The Language now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.