Table of contents
TOC
Collapse the table of content
Expand the table of content

Compiler Constants

office 365 dev account|Last Updated: 6/12/2017
|
1 Contributor

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 #If...Then...#Else directive except that they are global inscope; 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:

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

This applies to both Winx and VBAx constants. On 16-bit development platforms, the compiler constants are defined as follows:

ConstantValueDescription
Win16TrueIndicates development environment is 16-bit compatible.
Win32FalseIndicates that the development environment is not 32-bit compatible.
Win64FalseIndicates that the development environment is not 64-bit compatible.

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

ConstantValueDescription
Vba6TrueIndicates that the development environment is Visual Basic for Applications, version 6.0 compatible.
Vba6FalseIndicates that the development environment is not Visual Basic for Applications, version 6.0 compatible.
Vba7TrueIndicates that the development environment is Visual Basic for Applications, version 7.0 compatible.
Vba7FalseIndicates that the development environment is not Visual Basic for Applications, version 7.0 compatible.
Win16FalseIndicates that the development environment is not 16-bit compatible.
Win32TrueIndicates that the development environment is 32-bit compatible.
Win64FalseIndicates that the development environment is not 64-bit compatible.
MacTrueIndicates that the development environment is Macintosh.
MacFalseIndicates that the development environment is not Macintosh.

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

ConstantValueDescription
Vba6TrueIndicates that the development environment is Visual Basic for Applications, version 6.0 compatible.
Vba6FalseIndicates that the development environment is not Visual Basic for Applications, version 6.0 compatible.
Vba7TrueIndicates that the development environment is Visual Basic for Applications, version 7.0 compatible.
Vba7FalseIndicates that the development environment is not Visual Basic for Applications, version 7.0 compatible.
Win16FalseIndicates development environment is not 16-bit compatible.
Win32TrueIndicates that the development environment is 32-bit compatible.
Win64TrueIndicates that the development environment is 64-bit compatible.
MacTrueIndicates that the development environment is Macintosh.
MacFalseIndicates that the development environment 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.

© 2017 Microsoft