Skip to Main Content

Use VBA Constants and Enums

VBA contains many internal constants and enumerated types to provide consistency and more readable code. Some programmers like to bypass these internal types and use the numeric equivalents. The most common of these practices is to use 0 and 1 for the Boolean FALSE and TRUE.

You might also be tempted to do (or run into code that does) something like this:


If MsgBox("Do you want to continue", 4) = 6 Then
...
Else
...
End If

Instead of this:


If MsgBox("Do you want to continue", vbYesNo) = vbYes Then
...
Else
...
End If

Just don’t do it.

Leave a Reply

Your email address will not be published. Required fields are marked *