如何将32位VBA代码转换为64位VBA代码 [英] How to convert 32 bit VBA code into 64 bit VBA code
问题描述
我正在尝试运行宏代码,但是由于我使用的是64位Excel 2016,因此该代码无法正常工作.请帮助我解决此问题.
Im trying to run a macro code but since I'm using a 64 bit Excel 2016 this code is not working. Please help me how to fix this.
Private Declare Function FindWindowEx Lib "User32" Alias "FindWindowExA" _
(ByVal hWnd1 As Long, ByVal hWnd2 As Long, ByVal lpsz1 As String, _
ByVal lpsz2 As String) As Long
Private Declare Function IIDFromString Lib "ole32" _
(ByVal lpsz As Long, ByRef lpiid As GUID) As Long
Private Declare Function AccessibleObjectFromWindow Lib "oleacc" _
(ByVal hWnd As Long, ByVal dwId As Long, ByRef riid As GUID, _
ByRef ppvObject As Object) As Long
推荐答案
这些应在64位Excel上运行
These should work on 64 bit Excel
Private Declare PtrSafe Function FindWindowEx Lib "user32" Alias "FindWindowExA" _
(ByVal hWnd1 As LongPtr, ByVal hWnd2 As LongPtr, ByVal lpsz1 As String, _
ByVal lpsz2 As String) As LongPtr
Private Declare PtrSafe Function IIDFromString Lib "ole32" _
(ByVal lpsz As LongPtr, ByRef lpiid As GUID) As LongPtr
Private Declare PtrSafe Function AccessibleObjectFromWindow Lib "oleacc" _
(ByVal Hwnd As LongPtr, ByVal dwId As LongPtr, ByRef riid As GUID, _
ByRef ppvObject As Object) As LongPtr
如果需要同时运行它们,则可以使用以下#If VBA7
If you need it to run on both you can use the following #If VBA7
#If VBA7 Then
'64 bit declares here
#Else
'32 bit declares here
#End If
可以在此处找到PtrSafe Win32 API声明的很好的资源: Win32API_PtrSafe.txt
A nice resource for PtrSafe Win32 API declares can be found here: Win32API_PtrSafe.txt
我不太确定IIDFromString
和AccessibleObjectFromWindow
,但是我认为它们应该是subs
而不是functions
.并且lpsz
应该是String
,如下所示.也许任何人都可以确认这一点?
I'm not quite sure about the IIDFromString
and AccessibleObjectFromWindow
but I think they should be subs
instead of functions
. And lpsz
should be String
like below. Maybe anyone can confirm this?
Private Declare PtrSafe Sub IIDFromString Lib "ole32" ( _
ByVal lpsz As String, ByRef lpiid As GUID)
Private Declare PtrSafe Sub AccessibleObjectFromWindow Lib "oleacc" _
(ByVal Hwnd As LongPtr, ByVal dwId As LongPtr, ByRef riid As GUID, _
ByRef ppvObject As Object)
这篇关于如何将32位VBA代码转换为64位VBA代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!