64位office Access使用网站上下载的例子出错的解决方法。
问题描述:
有学员在网站(www.accessoft.com)下载示例使用64位office运行的的时候会出现提示错误。
这个是因为示例的模块里面引用API的代码只能在32位office运行,在64位office Access不能运行导致的。
解决方案:
使用下面链接的方法可以把代码修正过来,在64位开发环境中, Declare 语句应与 PtrSafe 关键字一起使用
http://www.accessoft.com/article-show.asp?id=17995
另外也可以直接使用如下代码替换原来的代码,那样就不管32位还是64位office都没有问题了
'API函数声明
#If VBA7 Then
Public Declare PtrSafe Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" (ByVal hWnd As LongPtr, ByVal lpOperation As String, ByVal lpFile As String, ByVal lpParameters As String, ByVal lpDirectory As String, ByVal nShowCmd As LongPtr) As LongPtr
Public Declare PtrSafe Function SetCursor Lib "user32" (ByVal hCursor As LongPtr) As LongPtr
Public Declare PtrSafe Function LoadCursorByNum Lib "user32" Alias "LoadCursorA" (ByVal hInstance As LongPtr, ByVal lpCursorName As LongPtr) As LongPtr
#Else
Public Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" (ByVal hWnd As Long, ByVal lpOperation As String, ByVal lpFile As String, ByVal lpParameters As String, ByVal lpDirectory As String, ByVal nShowCmd As Long) As Long
Public Declare Function SetCursor Lib "user32" (ByVal hCursor As Long) As Long
Public Declare Function LoadCursorByNum Lib "user32" Alias "LoadCursorA" (ByVal hInstance As Long, ByVal lpCursorName As Long) As Long
#End If
注意:
示例中的[系统模块]不能拷到平台中使用,因为平台中已经有了这个功能,否则会出现二义性错误。