【问题标题】:Excel 2016 conditional compilation with 32-bit flags带有 32 位标志的 Excel 2016 条件编译
【发布时间】:2017-02-10 08:03:49
【问题描述】:

在我今天通过更新获得的 OSX 上新的 64 位 Excel 2016 版本中,在检查未定义 PtrSafe 的函数定义时似乎没有遵循条件编译(如32 位平台)。在这个例子中,我们对不同平台的同一个函数有不同的定义,当 Excel 加载加载项时,它会死掉并抱怨第三个定义在函数声明中没有 PtrSafe(但当然不是因为它适用于 32 位平台)。

有没有什么方法可以让 Excel 在 VBA 中遇到此代码时不会死机?或者这只是 OSX 上 64 位 Excel 2016 中的一个错误?对我来说似乎是一个明显的错误。我在哪里报告 Excel 中的错误?

#If Mac Then
' Even though the functions are exported with a leading underscore, Excel 2011 for Mac doesn't want the leading underscore as part of name
Private Declare PtrSafe Function get_global_param_string_private Lib "libCoolProp.dylib" Alias "get_global_param_string" (ByVal param As String, ByVal Output As String, ByVal n As Integer) As Long
#ElseIf Win64 Then
Private Declare PtrSafe Function get_global_param_string_private Lib "CoolProp_xls_x64.dll" Alias "get_global_param_string" (ByVal param As String, ByVal Output As String, ByVal n As Integer) As Long
#Else
Private Declare Function get_global_param_string_private Lib "CoolProp_xls_std.dll" Alias "_get_global_param_string@12" (ByVal param As String, ByVal Output As String, ByVal n As Integer) As Long
#End If

【问题讨论】:

    标签: macos excel excel-2016 vba


    【解决方案1】:

    除非 API 函数本身对于 64 位和 32 位窗口不同,否则对 Windows 使用 VBA7 开关(从 Office 2010 开始)就足够了:

    #If Mac Then
    ' Even though the functions are exported with a leading underscore, Excel 2011 for Mac doesn't want the leading underscore as part of name
    Private Declare PtrSafe Function get_global_param_string_private Lib "libCoolProp.dylib" Alias "get_global_param_string" (ByVal param As String, ByVal Output As String, ByVal n As Integer) As Long
    #ElseIf VBA7 Then
    Private Declare PtrSafe Function get_global_param_string_private Lib "CoolProp_xls_x64.dll" Alias "get_global_param_string" (ByVal param As String, ByVal Output As String, ByVal n As Integer) As Long
    #Else
    Private Declare Function get_global_param_string_private Lib "CoolProp_xls_std.dll" Alias "_get_global_param_string@12" (ByVal param As String, ByVal Output As String, ByVal n As Integer) As Long
    #End If
    

    【讨论】:

    • 这没有回答问题,这与 excel 对没有 ptrsafe 的函数的混淆有关,因为它们适用于 32 位平台
    • 如果您使用 Excel 2010 或更高版本,ptrsafe 关键字可用于任何位数。请参阅jkp-ads.com/articles/apideclarations.asp 了解更多信息。
    • 我不知道那个!!感谢您提供有关支持的版本的信息
    猜你喜欢
    • 2019-01-22
    • 1970-01-01
    • 2017-03-26
    • 1970-01-01
    • 2011-04-12
    • 1970-01-01
    • 2014-05-31
    • 1970-01-01
    • 2022-09-22
    相关资源
    最近更新 更多