Detemine by VBA if Excel is 64 bit or 32 bit

Paul Sansom

Board Regular
Joined
Jan 28, 2013
Messages
178
Office Version
  1. 2021
  2. 2016
Platform
  1. Windows
Hi I have looked through the old posts on this and I a not clear that this is checking for Excel

I want to perform actions based on 32bit or 64bit version of Excel not machine capability
I have 2 users both using 32bit Excel but 1 has 32bit operating system and the other 64bit.

Code:
    [URL=https://www.mrexcel.com/forum/usertag.php?do=list&action=hash&hash=If]#If[/URL]  Win64 Then
        Sheet11.Range("Win_64_32") = 64        
    [URL=https://www.mrexcel.com/forum/usertag.php?do=list&action=hash&hash=Else]#Else[/URL] 
        Sheet11.Range("Win_64_32") = 32    
    [URL=https://www.mrexcel.com/forum/usertag.php?do=list&action=hash&hash=End]#End[/URL]  If

Does this example code check Excel or Windows?
Cheers Paul
 

Excel Facts

How can you turn a range sideways?
Copy the range. Select a blank cell. Right-click, Paste Special, then choose Transpose.
I think I may have found my own answer...….
"The VBA7 compiler variable indicates whether we are in Excel 2007 or later, the first versions to support 64-bit versions.
The WIN64 compiler version indicates whether we are in a 64-bit version of Excel.
Contrary to what its name implies, WIN64 does not mean specifically that you are running Windows 64-bit.
It indicates whether you are in a 64-bit application. For example, if you are running 32-bit Excel on Windows 64-bit, the VBA7 constant will be True and the WIN64 constant will be False."

This is courtesy of cpearson.com
 
Last edited:
Upvote 0
@Paul Sansom

You can also take advantage of the LongPtr Type to find out at runtime whether excel is 32 or 64 bits.
Code:
Function ExcelBitness() As Byte
    Dim lngPtr As LongPtr
    ExcelBitness = IIf(LenB(lngPtr) = 4, 32, 64)
End Function

Test:
Code:
Sub Test()
    MsgBox ExcelBitness
End Sub

Late Note:
This only works for excel 2010 or later.
 
Last edited:
Upvote 0
Another way that works at runtime and also works for excel 2000 or later :

Code:
Function ExcelBitness() As Byte
    ExcelBitness = IIf(TypeName(AddressOf Dummy) = "Long", 32, 64)
End Function

Function Dummy()
End Function

Test:
Code:
Sub Test()
    MsgBox ExcelBitness
End Sub
 
Last edited:
Upvote 0
Yet another way that works at runtime and I think this function should now work in all versions of excel/vba :

Code:
Function ExcelBitness() As Byte
    Dim vHinstance As Variant
    
    On Error Resume Next
    vHinstance = Application.Hinstance
    ExcelBitness = IIf(Err = 0, 32, 64)
End Function
 
Upvote 0
Many thanks for all 3 versions. As all users are 2010 or above, solution 1 applies for me , but solutions 2&3 may be useful to others.
Paul
 
Upvote 0

Forum statistics

Threads
1,223,228
Messages
6,170,871
Members
452,363
Latest member
merico17

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top