【问题标题】:How to change vba Declaration statement to be compatible with Windows 64 bit如何更改 vba 声明语句以与 Windows 64 位兼容
【发布时间】:2015-05-04 13:07:18
【问题描述】:

我有一个模型,以前只有 32 位 Windows 的人使用,但现在用户正在升级到 64 位,我需要使下面的声明声明兼容两个系统:

'Import functions from external DLL's
Public Declare Function SendMailWithAttachments Lib "PostSMTP.xll" ( _
                       ByVal strServer As String, _
                       ByVal uPort As Integer, _
                       ByVal strFrom As String, _
                       ByVal strTo As String, _
                       ByVal strSubject As String, _
                       ByVal strBody As String, _
                       ByVal strAttachments As String) As Integer

我尝试在代码中包含 PtrSafe,但这仍然不起作用。这是我第一次不得不做出这样的改变,所以我不知道从哪里开始。任何反馈将不胜感激。

【问题讨论】:

  • 感谢您重新格式化...新手错误,因为这是我第一次发布问题...
  • 您收到错误消息了吗?
  • 是的,当64位用户运行时,错误是找不到文件(“PostSMTP.xll”)。无论是否包含 PtrSafe。
  • PtrSafe 只是其中的一部分。

标签: vba 32bit-64bit


【解决方案1】:

如您所知,Windows 有 64 位和 32 位版本。您可能知道也可能不知道 MS Office 有 32 位和 64 位版本。您(和您的 IT 员工)可能错过的是 Microsoft strongly recommends the 32-bit version of Office for most users, even when running 64-bit Windows.

这也是原因之一。

谢天谢地,这篇文章是为 Office 2010 编写的。虽然其中的大部分内容仍然适用于 Office 2013,并且一般建议仍然存在,但您现在至少现在可以修复您的 DECLARE 语句以使用 64-位办公室,如果你必须。这是 MSDN 文章,介绍了如何做到这一点:

https://msdn.microsoft.com/en-us/library/office/gg264421.aspx

您已经看过其中的一部分,但 PtrSafe 并不是故事的全部。它还涉及在正确的场景中使用正确的指针类型。此外,您正在使用 xll 文件,该文件本身是使用 VBA 编写的。 您还必须修改原始文件以正确使用 PtrSafe 和正确的 LongPtr 类型。如果您无法做到这一点,32 位版本的 Office 是您唯一的选择。

【讨论】:

  • 感谢您提供了非常丰富的信息。现在我能够让 IT 回滚到 32 位版本,同时我正在努力更新原始 xll。
【解决方案2】:

在函数声明中使用 PtrSafe 喜欢:

Public Declare PtrSafe Function

【讨论】:

    猜你喜欢
    • 2011-07-27
    • 2019-06-27
    • 1970-01-01
    • 1970-01-01
    • 2013-10-04
    • 2013-03-12
    • 1970-01-01
    • 2010-10-21
    • 2010-09-07
    相关资源
    最近更新 更多