How to Check if VBA is Running in 64-bit Mode
A simple function (or class property) that returns whether the VBA code is running under 32-bit mode or 64-bit mode.
This simple function will tell you whether the current VBA code is executing in 64-bit mode or 32-bit mode.
Please note that this code is checking the VBA bitness, not the operating system bitness. It is quite common for VBA to be running in 32-bit mode on a 64-bit Windows system.
While there are surely other uses for a function like this, I use it primarily as part of my automated error-logging routine.
The Code: As Function
'Returns True if the user is running 64-bit *VBA* ' This is *NOT* the same as the Windows bitness; ' 64-bit Windows can (and often does) run 32-bit VBA Public Function Is64bitVba() As Boolean #If Win64 Then Is64bitVba = True #End If End Function
The function makes use of the Win64 compiler constant. That constant did not get introduced until VBA 7 (Access 2010). However, the above code will still work in earlier versions of VBA because unrecognized compiler constants evaluate to False.
The Code: As Class Property
In my own code, I actually use
Is64bitVba as a property within my global singleton class, clsApp.
'Returns True if the user is running 64-bit *VBA* ' This is *NOT* the same as the Windows bitness; ' 64-bit Windows can (and often does) run 32-bit VBA Public Property Get Is64bitVba() As Boolean #If Win64 Then Is64bitVba = True #End If End Property
Here are the two approaches in action from the Immediate window: