How to find Your VBA Version?

The below code will get the VBA version detail using pre-compiler directives.

We cannot display the value in thee variables. But it can be used inside the #IF. Then we can print the required values.

Here is the code that can fetch VBA version along with Operating system installation bytes detail as well.

Function findVBAversion() As String
    Dim vbaVersion As String
    
    'Find VBA version
    #If VBA6 Then
        vbaVersion = "v6"
    #ElseIf VBA7 Then
        vbaVersion = "v7"
    #ElseIf Mac Then
        vbaVersion = "Mac"
    #End If
    
    'Check if 64-bit or 32-bit
    #If Win64 Then
        vbaVersion = vbaVersion & ",64-bit"
    #ElseIf Win32 Then
        vbaVersion = vbaVersion & ",32-bit"
    #Else
        vbaVersion = vbaVersion & ",16-bit"
    #End If
    
    'Return Value
    Debug.Print vbaVersion
    findVBAversion = vbaVersion
End Function

Sometimes, the code could run in a iOS environment also. That is why a display condition is added to identify Mac computers as well. This is tested in Excel macro coding environment. It should work in other office VB editors as well.

Why we need to Find VBA Version?

This is required in cases, where we develop a Excel or VBA app, that needs to run in multiple version of VBA installations.

Note: Detailed info on these compiler directive constants are explained in this page – click here to read.

If it is not used, then the end user will encounter errors & You need to put a fix later. But it is tough to deliver a product for each version. Instead same code can be made to run in any installed version of VBA.

With the upgrade of 32 bit machines to 64 bit, there is been a lot of code changes in the VBA world. As long as all the 32 bit machines are upgraded and to VBA7, these pre-processor directives will be very useful.

Within the VBA editor, the lines inside the IF conditions will be highlighted as red. It signifies that the editor has identified those code as incorrect or incompatible code. But, you don’t have to worry about it. The code will just run fine. The execution will not come inside the part where there are incompatible codes.