Checking Office bittness with VBA (1 Viewer)

KitaYama

Well-known member
Local time
Tomorrow, 01:26
Joined
Jan 6, 2022
Messages
1,560
I've seen some experts use a conditional IF to check for Office bittness as following
Code:
#If VBA7 ....... #Else ...... #End If

but it's been always a question for me why it doesn't work on my PCs.
For me #If VBA7 always returns true for both 32 & 64 bit.
If I want to check for office bittness, I have to use #If WIN64.

Is there any reason for this?
Thanks.

2023-07-18_11-13-55.png
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Tomorrow, 00:26
Joined
May 7, 2009
Messages
19,246
use your last option, #If Win64.
this is enquiring if your Office is 64 bit (contrary to it's name).

Code:
Private Sub test()
    Dim strRet As String
    strRet = "32"
    #If Win64 Then
        strRet = "64"
    #End If
    Debug.Print strRet & " bit Office installed"
End Sub
 

KitaYama

Well-known member
Local time
Tomorrow, 01:26
Joined
Jan 6, 2022
Messages
1,560
use your last option, #If Win64.
this is enquiring if your Office is 64 bit (contrary to it's name).

Code:
Private Sub test()
    Dim strRet As String
    strRet = "32"
    #If Win64 Then
        strRet = "64"
    #End If
    Debug.Print strRet & " bit Office installed"
End Sub
@arnelgp Glad to see you're back.
My main question was why #IF VBA7 is used by some experts while it doesn't work in certain situations.
And what are those situations.


Thanks.
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Tomorrow, 00:26
Joined
May 7, 2009
Messages
19,246
the conditional compiler directive:
#If VBA7
is a test whether your office installed (therefore its VBA) is Newer (i think A2007 and above).
it does not test for bitness.

you need to test VBA7 because some API declaration (like window handle),
it should be declared As LongPtr (not Long).
when you declare this way, MSA will determine the space
it need to allocate (whether Long or LongLong, etc).
 

isladogs

MVP / VIP
Local time
Today, 17:26
Joined
Jan 14, 2017
Messages
18,252
As @arnelgp said, the #VBA7 compiler constant (introduced in A2010) works in both 32-bit and 64-bit Access from that version onwards.
The #Else part is only needed for use with A2007 or earlier.
 

KitaYama

Well-known member
Local time
Tomorrow, 01:26
Joined
Jan 6, 2022
Messages
1,560
As @arnelgp said, the #VBA7 compiler constant (introduced in A2010) works in both 32-bit and 64-bit Access from that version onwards.
The #Else part is only needed for use with A2007 or earlier.
I'm sorry, But I'm not sure I can understand.
In plain words, Is it correct if I assume in recent versions of Access, I can not use #IF VBA7 to determine the bitness of the installed application?

Thanks.
 

AHeyne

Registered User.
Local time
Today, 18:26
Joined
Jan 27, 2006
Messages
93
In manner of the bitness of your Microsoft Office product you can use the conditional compiler directive VBA7 only indirectly:

Code:
#If VBA7 Then
    Debug.Print "I'm running VBA7, what has been introduced with Microsoft Office 2010."
    Debug.Print "Because all versions from Microsoft Office 2010 on are available in 32 and 64 bitness, this can be a 32- or 64-bit environment."
#Else
    Debug.Print "I am using a VBA version from before Microsoft Office 2010."
    Debug.Print "Because versions older than Microsoft Office 2010 are only available in 32-bit, this can only be a 32-bit environment."
#End If

To really determine the bitness use this:

Code:
#If Win64 Then
    Debug.Print "This is a 64-bit environment."
#Else
    Debug.Print "This is a 32-bit environment."
#End If

Edit:
Even if the name of the conditional compiler directive Win64 suggests that it would be the bitness of Microsoft Windows, it is definitely not so. It reflects the bitness of Microsoft Office/VBA.
 
Last edited:

Users who are viewing this thread

Top Bottom