将32位Access系统部署到64位Office计算机

时间:2014-09-02 08:36:54

标签: vba ms-office 32bit-64bit

我正在从运行Access 2010的32位Office计算机编译Access数据库。我正在部署为.accdr文件,以便在Access 2010 Runtime中使用。我的推荐是:

VBE7.DLL

MSACC.OLB

stdole2.tlb

ACEDAO.DLL

EXCEL.EXE

msxml6.dll

我需要部署到一系列平台,包括64位2010年,2013年等等。

我认为大多数引用没有问题,因为部署的系统将使用Access 2010 Runtime。但是,Excel会给我一个问题。我曾尝试在运行中注册Excel引用(实际上是所有引用,以防任何其他版本因机器而异),但似乎我无法从32位系统注册64位版本的Excel。或者我可以吗?

另外,如果我使用Runtime 2010,是否仍需要更改API调用(使用PtrSafe关键字)?

以下是我发布的一些API调用:

Declare Function aht_apiGetOpenFileName Lib "comdlg32.dll" 
    Alias "GetOpenFileNameA" (OFN As tagOPENFILENAME) As Boolean

Private Declare Function apiGetLocaleInfo Lib "kernel32" 
    Alias "GetLocaleInfoA" (ByVal Locale As Long, ByVal LCType As Long, ByVal lpLCData As String, ByVal cchData As Long) As Long

Private Declare Function LoadLibraryRegister Lib "kernel32" Alias "LoadLibraryA" (ByVal lpLibFileName$) As Long

Public Declare Function SetDllDirectoryA Lib "kernel32" (ByVal lpPathName As String) As Long

Private Declare Function GetProcAddressRegister Lib "kernel32" Alias _
"GetProcAddress" (ByVal hModule&, ByVal lpProcName$) As Long

Private Declare Function CreateThreadForRegister Lib "kernel32" Alias "CreateThread" (lpThreadAttributes As Any, ByVal dwStackSize&, ByVal lpStartAddress&, ByVal lpparameter&, ByVal dwCreationFlags&, ThreadID&) As Long

1 个答案:

答案 0 :(得分:1)

您需要确保代码能够在两种环境中运行。所以你可以像我一样使用条件编译的建议。

我通常在标准模块中使用所有库调用。你应该能够做到以下几点:

#If Win64 = 1 And VBA7 = 1 Then
    Declare PtrSafe Function aht_apiGetOpenFileName Lib "comdlg32.dll" 
        Alias "GetOpenFileNameA" (OFN As tagOPENFILENAME) As Boolean

    Private Declare PtrSafe Function apiGetLocaleInfo Lib "kernel32" 
        Alias "GetLocaleInfoA" (ByVal Locale As Long, ByVal LCType As Long, ByVal lpLCData As String, ByVal cchData As Long) As Long

    Private Declare PtrSafe Function LoadLibraryRegister Lib "kernel32" Alias "LoadLibraryA" (ByVal lpLibFileName$) As Long

    Public Declare PtrSafe Function SetDllDirectoryA Lib "kernel32" (ByVal lpPathName As String) As Long

    Private Declare PtrSafe Function GetProcAddressRegister Lib "kernel32" Alias _
    "GetProcAddress" (ByVal hModule&, ByVal lpProcName$) As Long

    Private Declare PtrSafe Function CreateThreadForRegister Lib "kernel32" Alias _
    "CreateThread" (lpThreadAttributes As Any, ByVal dwStackSize&, ByVal lpStartAddress&, _
    ByVal lpparameter&, ByVal dwCreationFlags&, ThreadID&) As Long
#Else
    Declare Function aht_apiGetOpenFileName Lib "comdlg32.dll" 
        Alias "GetOpenFileNameA" (OFN As tagOPENFILENAME) As Boolean

    Private Declare Function apiGetLocaleInfo Lib "kernel32" 
        Alias "GetLocaleInfoA" (ByVal Locale As Long, ByVal LCType As Long, ByVal lpLCData As String, ByVal cchData As Long) As Long

    Private Declare Function LoadLibraryRegister Lib "kernel32" Alias "LoadLibraryA" (ByVal lpLibFileName$) As Long

    Public Declare Function SetDllDirectoryA Lib "kernel32" (ByVal lpPathName As String) As Long

    Private Declare Function GetProcAddressRegister Lib "kernel32" Alias _
    "GetProcAddress" (ByVal hModule&, ByVal lpProcName$) As Long

    Private Declare Function CreateThreadForRegister Lib "kernel32" Alias _
    "CreateThread" (lpThreadAttributes As Any, ByVal dwStackSize&, ByVal lpStartAddress&, _
    ByVal lpparameter&, ByVal dwCreationFlags&, ThreadID&) As Long
#End If