API functions in Office 64bit

Some applications created for 32-bit VBA can give problems if opened with Office 64-bit, in my case the below error was occurred while I attempted to open with Office 2010 64-bit the program “EPO IPscore” (a database in Access):

Errore API 64 bit

The errors detected were the following:

– I Error

Codice VBA

– II Error

Errore codice VBA

 

For the I error:

 la declaration for the 32 bit version was:

  • Declare Function GetOpenFileName Lib “comdlg32.dll” _ Alias “getOpenFileNameA” (pOpenfilename As OPENFLENAME) As Long

for the 64-bit version it has become:

  • Declare PtrSafe Function GetOpenFileName Lib “comdlg32.dll” _ Alias “getOpenFileNameA” (pOpenfilename As OPENFLENAME) As Long”

In the second case, the error was in “API Sleep”:

In 32 bit version it was:

  • Public Declare Sub Sleep Lib “kernel32” ( _ByVal dwMilliseconds As Long)

while for the 64-bit version we add the attribute PtrSafe,:

  • Public Declare PtrSafe Sub Sleep Lib “kernel32” ( _ByVal dwMilliseconds As Long).

www.jkp-ads.com is a useful link to see how the correct syntax of VBA can be applied on Office 64-bit is: www.jkp-ads.com

As a general rule, as shown in the link above, issues management functions can be solved with the following systems:

  • add the attribute “PtrSafe” after the declaration  “declare
  • change the variable from “Long” to “LongPtr”

Lascia un commento