gpt4 book ai didi

excel - 确保您的 VBA 代码兼容 64 位

转载 作者:行者123 更新时间:2023-12-02 15:28:00 25 4
gpt4 key购买 nike

我的 Mircosoft Office 2010 是 x86,但当我尝试运行 oe VBA 时,收到一条错误消息,指出它不兼容 x64。

我有这个代码:

Private Declare Function SHFileOperation Lib "shell32.dll" Alias _
"SHFileOperationA" (lpFileOp As SHFILEOPSTRUCT) As Long

Private Declare Function PathIsNetworkPath Lib "shlwapi.dll" _
Alias "PathIsNetworkPathA" ( _
ByVal pszPath As String) As Long

Private Declare Function GetSystemDirectory Lib "kernel32" _
Alias "GetSystemDirectoryA" ( _
ByVal lpBuffer As String, _
ByVal nSize As Long) As Long

Private Declare Function SHEmptyRecycleBin _
Lib "shell32" Alias "SHEmptyRecycleBinA" _
(ByVal hwnd As Long, _
ByVal pszRootPath As String, _
ByVal dwFlags As Long) As Long

Private Const FO_DELETE = &H3
Private Const FOF_ALLOWUNDO = &H40
Private Const FOF_NOCONFIRMATION = &H10
Private Const MAX_PATH As Long = 260

Private Type SHFILEOPSTRUCT
hwnd As Long
wFunc As Long
pFrom As String
pTo As String
fFlags As Integer
fAnyOperationsAborted As Boolean
hNameMappings As Long
lpszProgressTitle As String
End Type

''''''''''''''''''''''''''''''''''''''
' Download API function.
''''''''''''''''''''''''''''''''''''''
Private Declare Function URLDownloadToFile Lib "urlmon" Alias _
"URLDownloadToFileA" ( _
ByVal pCaller As Long, _
ByVal szURL As String, _
ByVal szFileName As String, _
ByVal dwReserved As Long, _
ByVal lpfnCB As Long) As Long

我尝试将每个私有(private)声明函数更改为私有(private)声明 PtrSafe 函数

但是当我尝试加载代码时,我的 Excel 没有响应。

有人知道解决办法吗?

谢谢

求解器:只需将 Long 也更改为 LongPtr

最佳答案

Long 是一个 32 位整数,但在 64 位版本的 Office 下,调用 Windows API 句柄和指针将是 64 位宽,因此上述 API 将失败。

VBA7 中提供了

LongPtr 来适应这一点,Microsoft 的 Compatibility Guide描述了如何使代码在 x86/x64 版本的 Office 下运行。

关于excel - 确保您的 VBA 代码兼容 64 位,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23845458/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com