Linker IT Software
Google
Web www.oraxcel.com
menubar-top-links menubar-top-rechts
Home Help Search Login
Welcome, Guest. Please Login.
SQL*XL: Database to Excel bridge litLIB: Excel power functions pack ExcelLock: Locking and securing your valuable Excel spreadsheets encOffice: Protect your Excel file easy and safe encOffice: Protect your Excel file easy and safe
Pages: 1
Check whether Office is 32 or 64 bits (Read 11286 times)
Gerrit-Jan Linker
YaBB Administrator
*****




Posts: 75
Check whether Office is 32 or 64 bits
27.08.10 at 13:42:56
 
Check whether Office is 32 or 64 bits
 
There is no function to detect whether MS Office 2010 is x86 or x64. in VBA you can use compiler constants VBA7 and Win64 although this still doesn't tell you whether Office is 64 bits or not. Outlook 2010 has a registry key called bitness in x64 installations which has the value x64. So if you use Outlook you can use that. For the other office applications I have only found the following way to tell whether the application is x64 or x86.
 
Application.Hinstance / Application.HinstancePtr
 
In 32bit versions both have the same value. In the 64bit version the Hinstance value is probably a LongPtr. Assiging this hinstance to a long will fail only in 64bits versions, et voila! our test for 64 bits.
 
VB/VBA code:
 
Code:
Private Function m_IsExcelx64(ExcelApp As Object) As Boolean
    Dim l As Long
    
    l = -1
    On Error Resume Next
    l = ExcelApp.hInstance
    On Error GoTo 0
    
    If l = -1 Then
	  m_IsExcelx64 = True
    Else
	  m_IsExcelx64 = False
    End If
End Function 

Back to top
 
« Last Edit: 03.09.10 at 11:04:54 by Gerrit-Jan Linker »  

Gerrit-Jan Linker
Linker IT Software
Email WWW Gerrit-Jan Linker   IP Logged
uliman24
YaBB Newbies
*


I Love SQL*XL

Posts: 0
Re: Check whether Office is 32 or 64 bits
Reply #1 - 03.09.10 at 08:25:24
 
Thank you for the solution in excel.
But I have the same problem with word. Word-Application have no property "Hinstance".
I can't find a property as LongPtr in word.
Can you help me?
Back to top
 
 
  IP Logged
Gerrit-Jan Linker
YaBB Administrator
*****




Posts: 75
Re: Check whether Office is 32 or 64 bits
Reply #2 - 03.09.10 at 11:03:51
 
Indeed, I did this for Excel. I was not aware that Word has no hInstance property. The best advice I can give is to compare the application object properties both for 32 and 64 bits to see whether you can find a property that is different and from which you can derive the bitness.
 
If you are in VBA in Word/Excel then you can use condictional compilation constants (I believe they are VBA7 and Win64). When using it from outside Office in VB you must use other, indirect, techniques. And if you use both an addin inside Office and dlls/exes outside of Office you could expose addin properties that determine the bitness for you based on the compilation constants.
 
If you find anything useful, can you take the time to post it here too please?
Back to top
 
 

Gerrit-Jan Linker
Linker IT Software
Email WWW Gerrit-Jan Linker   IP Logged
uliman24
YaBB Newbies
*


I Love SQL*XL

Posts: 0
Re: Check whether Office is 32 or 64 bits
Reply #3 - 07.09.10 at 20:50:18
 
Thank you for your answer. My solution for word and excel is the property "ProductCode". It returns the GUID and also contains the information of x86 or x64. See the description of the numbering scheme for product code GUIDs in Office 2010 ... http://support.microsoft.com/kb/2186281/en-us
 
Code:
    Private Function IsOfficex64() As Boolean
	Dim result As Boolean = False

	Dim productKey As String = _application.ProductCode

	If String.Equals("1", productKey.Substring(20, 1), StringComparison.InvariantCulture) Then
	  result = True
	End If

	Return result
    End Function
 


Back to top
 
 
  IP Logged
Pages: 1