VBA – Determine MS Office/Application Bitness

Just a quick post. Have you ever needed to determine the bitness (x32 vs. x64) of Microsoft Office?

Yes, you can go File -> Account -> About Access and get the information from the pop-up dialog, but what if you want to determine this in your code, using a VBA function?

Using Conditional Compilation Directives

I started digging, thinking I could easily extract such information from the registry, boy was I wrong there. With all the variations of Office (MSI, CTR, …, x32, x64, …) it’s a nightmare to navigate! What a mess Microsoft has made for developers to have a hope in hell to keep all the registry keys and variations straight. Anyways, I ended up going back to basic, and the answer was Conditional Compilation Directives. With a simple Conditional Compilation Directives I had my answer.

'Determine if the current application, thus Office, is running in x32 or x64 bitness.
Function Office_Isx64() As Boolean
    #If Win64 Then
        Office_Isx64 = True
'    #Else
'        Office_Isx64 = False
    #End If
End Function

Nothing more to it than that.

Using the Application GUID

Based on Andreas Harke’s comment, you can also determine the bitness of an application by reading the 21st character of the application GUID. So you can do something like:

Function IsOffice32Bit() As Boolean
'https://docs.microsoft.com/en-us/office/troubleshoot/office-suite-issues/numbering-scheme-for-product-guid
'   p => 0=32-bit, 1=64-bit
    IsOffice32Bit = (Mid(Application.ProductCode, 21, 1) = 0)
End Function

6 responses on “VBA – Determine MS Office/Application Bitness

  1. Andreas Harke

    There is an easier way to check if it’s a 64bit version, without to have the application to get compiled again.

    Application.ProductCode at position 21 shows 0 for 32bit and 1 for 64bit version of Msaccess.exe

    1. Daniel Pineault Post author

      VBS makes it more difficult.

      Perhaps check the installation path and if it is in the “Program Files (x86)” folder you know it is 32-bit, otherwise it is a 64-bit installation.

      Perhaps try something like:

      sRegKey = "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\MSACCESS.EXE\Path"
      sPath = WScript.CreateObject("WScript.Shell").RegRead(sRegKey) 
      
      If InStr(sPath, "Program Files (x86)") <> 0 Then
      	Msgbox "32-bit Installation of Access."
      Else
      	Msgbox "64-bit Installation of Access."
      End If
  2. Lorenzo Garuglieri

    works. Tomorrow I’ll try it in the office at least I can find it even with the 32 versions.
    Also I tried, via VBS that the above command, (Function IsOffice32Bit) and that works too.
    What do you advise?
    Thank you

    Lorenzo