5

I know that I can use conditional compilation in VBA to differentiate between the 64bit and the 32bit version (using #If VBA7 Then ...).

Is there also a build in constant similar to Application.Version so that I can differentiate between Excel 2013/2010/2007/... etc. at compile time?

Also, is there a list of available existing compiler constants? So far I found VBA7 and Win64 (e.g. from this article) - but are there any other ones?

Community
  • 1
  • 1
Peter Albert
  • 16,917
  • 5
  • 64
  • 88
  • 3
    I'm unaware of any built in constants - the standard method is to use `Val(Application.Version)` – brettdj Jan 29 '13 at 10:48
  • Pity that it cant be broken down at compile time. but I guess that's just the way it is... – Peter Albert Jan 29 '13 at 10:57
  • 1
    The VBA7 constant doesn't tell you if you're using a 64-bit application. It tells you if you're using at least VBA7 (which could be a 32-bit or 64-bit application). The Win64 constant tells you if you're using a 64-bit application. – someprogrammer Apr 04 '18 at 14:15

2 Answers2

5

From this link, you have the following constants:

VBA6
VBA7
Win64
Win32
Win16
Mac
iDevlop
  • 24,841
  • 11
  • 90
  • 149
1

Not to the version granularity questioned, but I had a need to separate Office 365/XL16- specific code from its predecessors. VBA7 is backwards compatible with VBA6, and VBA6 knows nothing of VBA7. We can use this to our advantage.

Sub testit()
#If VBA6 And VBA7 Then
   Debug.Print "Cool!" 'XL16 vba code
#Else
   Debug.Print "Yeah!" 'Not XL16 vba code
#End If
End Sub

XL14 and below evaluate #If as if true/false, XL16 as true/true. If it's just #If VBA7, XL14 attempts to compile the XL16 code. I don't know why, but that's how it tested.

David Buck
  • 3,752
  • 35
  • 31
  • 35
Mick536
  • 19
  • 1