Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Declare PtrSafe Compatibility in Excel

Tags:

excel

vba

I am using this statement in VBA

Private Declare PtrSafe Function GetTimeZoneInformationAny Lib "kernel32" Alias _
  "GetTimeZoneInformation" (buffer As Any) As Long

This works fine with:

  • Win 64-bit, Excel 2010 64-bit
  • Win 64-bit, Excel 1010 32-bit

However my client reported a compile error on the word PtrSafe. He is using Excel 2010.

I am not sure why this happens. any ideas?

like image 357
JoaMika Avatar asked Mar 18 '23 23:03

JoaMika


1 Answers

ok I have re-written this like:

#If VBA7 Then
Private Declare PtrSafe Function GetTimeZoneInformationAny Lib "kernel32" Alias "GetTimeZoneInformation" (buffer As Any) As Long
#Else
Private Declare Function GetTimeZoneInformationAny Lib "kernel32" Alias "GetTimeZoneInformation" (buffer As Any) As Long
#End If

This gave a compile error on the second line in Excel 2010 64-bit and the line remained colored red but when I compile again the error doesn't show up anymore. Is this how Excel behaves?

like image 163
JoaMika Avatar answered Mar 28 '23 15:03

JoaMika