我可以在办公室的 Excel 2007 中使用这些代码,但为什么我不能在 Excel 2016 中使用它?
它说它不是基于 64 位构建的,但我该如何转换它?下面的代码以红色突出显示。
Private Declare Function FindWindow Lib "User32" _
Alias "FindWindowA" ( _
ByVal lpClassName As String, _
ByVal lpWindowName As String) As Long
Private Declare Function GetWindowLong Lib "User32" _
Alias "GetWindowLongA" ( _
ByVal hwnd As Long, _
ByVal nIndex As Long) As Long
Private Declare Function SetWindowLong Lib "User32" _
Alias "SetWindowLongA" (ByVal hwnd As Long, _
ByVal nIndex As Long, _
ByVal dwNewLong As Long) As Long
Private Declare Function DrawMenuBar Lib "User32" ( _
ByVal hwnd As Long) As Long
最佳答案
我发现 x64 系统的等效项:
Private Declare PtrSafe Function FindWindow Lib "user32" _
Alias "FindWindowA" ( _
ByVal lpClassName As String, _
ByVal lpWindowName As String) As LongPtr
#If Win64 Then
Private Declare PtrSafe Function GetWindowLongPtr Lib "user32" _
Alias "GetWindowLongPtrA" ( _
ByVal hWnd As LongPtr, _
ByVal nIndex As Long) As LongPtr
#Else
Private Declare PtrSafe Function GetWindowLongPtr Lib "user32" _
Alias "GetWindowLongA" ( _
ByVal hWnd As LongPtr, _
ByVal nIndex As Long) As LongPtr
#End If
Private Declare PtrSafe Function SetWindowLongPtr Lib "user32" _
Alias "SetWindowLongPtrA" ( _
ByVal hWnd As LongPtr, _
ByVal nIndex As Long, _
ByVal dwNewLong As LongPtr) As LongPtr
Public Declare PtrSafe Function DrawMenuBar Lib "user32" ( _
ByVal hWnd As LongPtr) As Long
来源:https://www.jkp-ads.com/articles/apideclarations.asp
我没有尝试这些功能,我只是通过了这段代码,尽管您在答案中使用了版本,但它并没有以红色突出显示。
关于vba - 如何将32位Excel VBA代码转换为在64位Excel上运行?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51173667/