Compiler constants

Visual Basic for Applications defines constants for exclusive use with the #If...Then...#Else directive. These constants are functionally equivalent to constants defined with the #Const directive except that they are global in scope; that is, they apply everywhere in a project.

Note

Because Win32 returns True in both 32-bit and 64-bit development platforms, it is important that the order within the #If...Then...#Else directive returns the desired results in your code. For example, because Win32 returns True in 64-bit (Win32 is compatible in Win64 environments), checking for Win32 before Win64 results in the Win64 condition never running because Win32 returns True. The following order returns predictable results (this applies to both Winx and VBAx constants):

#If Win64 Then 
' Win64=true, Win32=true, Win16= false 
#ElseIf Win32 Then 
' Win32=true, Win16=false 
#Else 
' Win16=true 
#End If

On 16-bit development platforms, the compiler constants are defined as follows.

Constant Value Indicates that the development environment...
Win16 True Is 16-bit compatible.
Win32 False Is not 32-bit compatible.
Win64 False Is not 64-bit compatible.

On 32-bit development platforms, the compiler constants are defined as follows.

Constant Value Indicates that the development environment...
Vba6 True Is Visual Basic for Applications, version 6.0 compatible.
Vba6 False Is not Visual Basic for Applications, version 6.0 compatible.
Vba7 True Is Visual Basic for Applications, version 7.0 compatible.
Vba7 False Is not Visual Basic for Applications, version 7.0 compatible.
Win16 False Is not 16-bit compatible.
Win32 True Is 32-bit compatible.
Win64 False Is not 64-bit compatible.
Mac True Is Macintosh.
Mac False Is not Macintosh.

On 64-bit development platforms, the compiler constants are defined as follows.

Constant Value Indicates that the development environment...
Vba6 True Is Visual Basic for Applications, version 6.0 compatible.
Vba6 False Is not Visual Basic for Applications, version 6.0 compatible.
Vba7 True Is Visual Basic for Applications, version 7.0 compatible.
Vba7 False Is not Visual Basic for Applications, version 7.0 compatible.
Win16 False Is not 16-bit compatible.
Win32 True Is 32-bit compatible.
Win64 True Is 64-bit compatible.
Mac True Is Macintosh.
Mac False Is not Macintosh.

Note

These constants are provided by Visual Basic, so you cannot define your own constants with these same names at any level.

See also

Support and feedback

Have questions or feedback about Office VBA or this documentation? Please see Office VBA support and feedback for guidance about the ways you can receive support and provide feedback.