在Excel中声明PtrSafe兼容性

我在VBA中使用这个语句

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

这工作正常:

  • Win 64位,Excel 2010 64位
  • Win 64位,Excel 1010 32位

但是,我的客户报告PtrSafe一个编译错误。 他正在使用Excel 2010。

我不知道为什么会发生这种情况。 有任何想法吗?

好的,我已经重写了这样的:

 #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 

这在Excel 2010 64位的第二行中给出了一个编译错误,并且该行仍为红色,但是当我再次编译时,错误不再显示。 这是如何Excel的行为?