vba 在 Excel 中声明 PtrSafe 兼容性

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/26822004/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-12 05:10:36  来源:igfitidea点击:

Declare PtrSafe Compatibility in Excel

excelvba

提问by Joanna Mikalai

I am using this statement in VBA

我在 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
  • Win 64 位,Excel 2010 64 位
  • Win 64 位,Excel 1010 32 位

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

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

I am not sure why this happens. any ideas?

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

回答by Joanna Mikalai

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?

这在 Excel 2010 64 位的第二行出现编译错误,该行保持红色,但当我再次编译时,错误不再出现。这是 Excel 的行为方式吗?