設(shè)為首頁收藏本站Access中國

Office中國論壇/Access中國論壇

 找回密碼
 注冊

QQ登錄

只需一步,快速開始

返回列表 發(fā)新帖
查看: 16006|回復(fù): 5
打印 上一主題 下一主題

[API] 【源碼】聲明32位和64位Access、Excel等VBA兼容的API函數(shù)的方法

[復(fù)制鏈接]

點擊這里給我發(fā)消息

跳轉(zhuǎn)到指定樓層
1#
發(fā)表于 2015-4-18 11:32:32 | 只看該作者 回帖獎勵 |倒序瀏覽 |閱讀模式
1.在聲明中加上  PtrSafe 關(guān)鍵字
2.加上VBA7 及Win64的判斷
Declare 語句 PtrSafe 關(guān)鍵字(可參考VBA幫助)
帶有 PtrSafe 關(guān)鍵字的 Declare 語句為建議的語法。要使包括 PtrSafe 的 Declare 語句能同時在 32 位和 64 位平臺上的 VBA7 開發(fā)環(huán)境中正確運行,必須先將 Declare 語句中所有需要存儲 64 位數(shù)的數(shù)據(jù)類型(參數(shù)和返回值)更新為使用 LongLong(對于 64 位整數(shù))或 LongPtr(對于指針和句柄)。為確保與 VBA 版本 6 和更早版本的向后兼容性,請使用下面的構(gòu)造:

#If Vba7 Then
Declare PtrSafe Sub...
#Else
Declare Sub...
#EndIf


示例1:
  1. #If VBA7 Then  ' 64位
  2.     Private Declare PtrSafe Function apisndPlaySound Lib "winmm.dll" Alias "sndPlaySoundA" (ByVal lpszSoundName As String, ByVal uFlags As Long) As Long
  3.     Private Declare PtrSafe Function apiPlaySound Lib "winmm.dll" Alias "PlaySoundA" (ByVal lpszName As String, ByVal hModule As Long, ByVal dwFlags As Long) As Long
  4. #Else
  5.     Private Declare Function apisndPlaySound Lib "winmm.dll" Alias "sndPlaySoundA" (ByVal lpszSoundName As String, ByVal uFlags As Long) As Long
  6.     Private Declare Function apiPlaySound Lib "winmm.dll" Alias "PlaySoundA" (ByVal lpszName As String, ByVal hModule As Long, ByVal dwFlags As Long) As Long
  7. #End If
復(fù)制代碼



'聲明32位和64位Access Excel等VBA兼容的API函數(shù)
  1. '當(dāng)VBA7和Win64都是True時(只有64的Excel才是這種情況),使用第一條Declare語句。在其他版本中,使用第二條Declare語句
  2. #If VBA7 And Win64 Then
  3.     Declare ptSafe Function GetWindowsDirectory Lib "kernel32" (ByVal ipBuffer As String, ByVal nSize As Long) As Long
  4. #Else
  5.     Declare Function GetWindowsDirectory Lib "kernel32" (ByVal ipBuffer As String, ByVal nSize As Long) As Long
  6. #End If

  7. GetWindowsDirectory()
  8. 說明
  9. 這個函數(shù)能獲取Windows目錄的完整路徑名。在這個目錄里,保存了大多數(shù)windows應(yīng)用程序文件及初始化文件
  10. 返回值
  11. Long類型,復(fù)制到lpBuffer的一個字串的長度。如lpBuffer不夠大,不能容下整個字串,就會返回lpBuffer要求的長度,零表示失敗。并且將出錯的信息存儲在GetLastError函數(shù)中,用戶可以通過調(diào)用GetLastError來得到錯誤信息。
  12. 參數(shù)表
  13. 參數(shù) 類型及說明
  14. lpBuffer String,指定一個字串緩沖區(qū),用于裝載Windows目錄名。除非是根目錄,否則目錄中不會有一個中止用的“\”字符
  15. nSize Long,lpBuffer字串的最大長度
  16. ​'獲取Windows文件夾路徑
  17. privateDeclare Function GetWindowsDirectory Lib "kernel32" Alias "GetWindowsDirectoryA" (ByVal lpBuffer As String, ByVal nSize As Long) As Long'在form窗體中聲明改函數(shù)
  18. Dim SWinDir As String '定義字符變量用來存儲路徑
  19. Dim Retn As Long ‘定義長整型變量存儲路徑的長度
  20. SWinDir = Space(255)’設(shè)定一個空串,長度為windows允許的最大長度,也可寫作:SWidir=String(255,0)
  21. Retn = GetWindowsDirectory(SWinDir, Len(SWinDir))‘獲取windows路徑的長度,swindir存儲了路徑
  22. SWinDir = Left(SWinDir, Retn)’去掉空白內(nèi)容。
復(fù)制代碼




示例2
  1. #If VBA7 Then
  2. '定義窗體樣式
  3. Private Declare PtrSafe Function FindWindow Lib "user32" Alias _
  4.     "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
  5. Private Declare PtrSafe Function SetWindowLong Lib "user32" Alias _
  6.     "SetWindowLongA" (ByVal Hwnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long
  7. #Else
  8. '定義窗體樣式
  9. Private Declare Function FindWindow Lib "user32" Alias _
  10.     "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
  11. Private Declare Function SetWindowLong Lib "user32" Alias _
  12.     "SetWindowLongA" (ByVal Hwnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long
  13. #End If
  14. 經(jīng)過以上處理, 在office2003、2007和2010版本 office2013、xp以上系統(tǒng)均可正常運行。
復(fù)制代碼



示例3
  1. If VBA7Then
  2.     Public Declare PtrSafe Function FindWindow Lib "user32.dll" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As LongLong
  3.     Public Declare PtrSafe Function ClientToScreen Lib "user32" (ByVal hWnd As LongLong, lpPoint As POINTAPI) As LongLong
  4.     Public Popup_Menu       As CommandBar       '指定彈出式菜單
  5.     Public LastSelect_Menu  As MSForms.Image    '最后選擇的菜單
  6.     Public MenuCount        As Integer          '子菜單數(shù)量
  7.     Public hForm            As Long             '窗口句柄
  8.     Public intLevel         As Integer          '級別標(biāo)識,用于設(shè)置Radio菜單(游戲菜單中:初級,中級,高級)
  9.     Public bAbortEnabled    As Boolean          '標(biāo)識放棄菜單項是否可用
  10.     Public bItemCheck       As Boolean          '標(biāo)識音效菜單是否CheckOn
  11.     Public bMenuSelected    As Boolean          '標(biāo)識菜單是否點擊
  12.     Public pt               As POINTAPI         '定義點
  13.     Public faceid As Integer                    '圖標(biāo)ID
  14.     Public faceidselect As Integer              '選擇的圖標(biāo)
  15.     Public fistid As Integer                    '第一個圖標(biāo)號
  16.     Public lastid As Integer                    '最后一個圖標(biāo)號
  17.     Public selectrow, selectcol As Integer
  18.     Public Mcro(50) As String
  19.     Public Declare PtrSafe Function GetWindowLong Lib "user32" Alias "GetWindowLongA" (ByVal hWnd As LongLong, ByVal nIndex As LongLong) As LongLong
  20.     Public Declare PtrSafe Function SetWindowLong Lib "user32" Alias "SetWindowLongA" (ByVal hWnd As LongLong, ByVal nIndex As LongLong, ByVal dwNewLong As LongLong) As LongLong
  21.     Public Const GWL_STYLE = (-16)
  22.     Public Const WS_THICKFRAME As Long = &H40000     '(回復(fù)大小)
  23.     Public Const WS_MINIMIZEBOX As Long = &H20000    '(最小化)
  24.     Public Const WS_MAXIMIZEBOX As Long = &H10000    '(最大化)
  25. Else
  26.     Public Declare Function FindWindow Lib "user32.dll" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
  27.     Public Declare Function ClientToScreen Lib "user32" (ByVal hWnd As Long, lpPoint As POINTAPI) As Long
  28.     Public Popup_Menu       As CommandBar       '指定彈出式菜單
  29.     Public LastSelect_Menu  As MSForms.Image    '最后選擇的菜單
  30.     Public MenuCount        As Integer          '子菜單數(shù)量
  31.     Public hForm            As Long             '窗口句柄
  32.     Public intLevel         As Integer          '級別標(biāo)識,用于設(shè)置Radio菜單(游戲菜單中:初級,中級,高級)
  33.     Public bAbortEnabled    As Boolean          '標(biāo)識放棄菜單項是否可用
  34.     Public bItemCheck       As Boolean          '標(biāo)識音效菜單是否CheckOn
  35.     Public bMenuSelected    As Boolean          '標(biāo)識菜單是否點擊
  36.     Public pt               As POINTAPI         '定義點
  37.     Public faceid As Integer                    '圖標(biāo)ID
  38.     Public faceidselect As Integer              '選擇的圖標(biāo)
  39.     Public fistid As Integer                    '第一個圖標(biāo)號
  40.     Public lastid As Integer                    '最后一個圖標(biāo)號
  41.     Public selectrow, selectcol As Integer
  42.     Public Mcro(50) As String
  43.     Public Declare Function GetWindowLong Lib "user32" Alias "GetWindowLongA" (ByVal hWnd As Long, ByVal nIndex As Long) As Long
  44.     Public Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" (ByVal hWnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long
  45.     Public Const GWL_STYLE = (-16)
  46.     Public Const WS_THICKFRAME As Long = &H40000     '(回復(fù)大小)
  47.     Public Const WS_MINIMIZEBOX As Long = &H20000    '(最小化)
  48.     Public Const WS_MAXIMIZEBOX As Long = &H10000    '(最大化)
  49. End If
復(fù)制代碼




分享到:  QQ好友和群QQ好友和群 QQ空間QQ空間 騰訊微博騰訊微博 騰訊朋友騰訊朋友
收藏收藏3 分享分享 分享淘帖 訂閱訂閱

點擊這里給我發(fā)消息

2#
 樓主| 發(fā)表于 2015-4-18 11:41:07 | 只看該作者
微軟的相關(guān)64位與32位兼容性的文章32 位和 64 位版本的 Office 2010 之間的兼容性Office 2010

摘自:https://msdn.microsoft.com/zh-cn/library/ee691831.aspx

摘要:針對處理大量數(shù)據(jù)的客戶,Microsoft 推出了 64 位版本的 Microsoft Office 2010。本文討論有關(guān) 32 位版本與新的 64 位版本和舊的 32 位 Office 應(yīng)用程序之間兼容性的問題,并提供了相應(yīng)的解決方案。(12 個打印頁)


上次修改時間: 2011年4月7日

Microsoft Corporation 的 Frank Rice

本文內(nèi)容
介紹 32 位和 64 位版本的 Microsoft Office 2010
將 32 位系統(tǒng)與 64 位系統(tǒng)進(jìn)行比較
介紹 VBA 7 基本代碼
ActiveX 控件和 COM 加載項兼容性
應(yīng)用程序編程接口兼容性
使用條件編譯屬性
結(jié)論
其他資源

2009 年 11 月

適用范圍: Excel 2010 | Office 2007 | Office 2010 | Open XML | PowerPoint 2010 | SharePoint Server 2010 | VBA | Visual Basic for Applications 7.0 (VBA 7.0) | Word 2010

內(nèi)容


[url=]介紹 32 位和 64 位版本的 Microsoft Office 2010[/url]

Microsoft Office 2010 system 同時具有 32 位和 64 位版本。64 位版本使您能夠處理更大的數(shù)據(jù)集。如果要在 Microsoft Excel 2010 中處理大量數(shù)字,則尤其需要使用此版本。

隨著新的 64 位版本 Microsoft Office 2010 的引入,Microsoft 發(fā)布了稱為 Microsoft Visual Basic for Applications 7.0 (VBA 7) 的新版本的 Microsoft Visual Basic for Applications (VBA) 以同時處理 32 位和 64 位應(yīng)用程序。需要特別注意的是,本文中介紹的更改只適用于 64 位版本的 Microsoft Office 2010。如果使用的是 32 位版本的 Office 2010,則可以不加修改地使用以前版本的 Microsoft Office 中內(nèi)置的解決方案。

注釋

在安裝 Office 2010 時,默認(rèn)安裝的是 32 位版本,即使在 64 位系統(tǒng)上也是如此。您必須明確 選擇 Office 2010 64 位版本安裝選項。


在 VBA 7 中,必須更新現(xiàn)有 Windows 應(yīng)用程序編程接口 (API) 語句(Declare 語句)才能處理 64 位版本。另外,還必須更新這些語句使用的用戶定義類型中的地址指針和顯示窗口句柄。本文將詳細(xì)討論這一點以及 32 位和 64 位版本的 Office 2010 之間的兼容性問題,并提供建議的解決方案。



[url=]將 32 位系統(tǒng)與 64 位系統(tǒng)進(jìn)行比較[/url]

使用 64 位版本的 Office 2010 構(gòu)建的應(yīng)用程序可以引用更大的地址空間,因此提供了使用比以往更多的物理內(nèi)存的機(jī)會,從而有可能減少將數(shù)據(jù)移入和移出物理內(nèi)存所需的開銷。

除了引用應(yīng)用程序用于存儲數(shù)據(jù)或存儲編程指令的物理內(nèi)存中的特定位置(又稱為指針)外,還可以使用地址來引用顯示窗口標(biāo)識符(稱為句柄)。根據(jù)您使用的是 32 位系統(tǒng)還是 64 位系統(tǒng),可確定指針或句柄的大。ㄒ宰止(jié)為單位)。

在使用 64 位版本的 Office 2010 運行現(xiàn)有解決方案時存在兩個基本問題:

  • Office 2010 中的本機(jī) 64 位進(jìn)程無法加載 32 位二進(jìn)制文件。在使用現(xiàn)有 Microsoft ActiveX 控件和現(xiàn)有加載項時,這被認(rèn)為是一個常見問題,

  • VBA 以前不具有指針數(shù)據(jù)類型,因此,開發(fā)人員使用 32 位變量來存儲指針和句柄。但現(xiàn)在在使用 Declare 語句時,這些變量會截斷 API 調(diào)用返回的 64 位值。




[url=]介紹 VBA 7 基本代碼[/url]

VBA 7 是新的基本代碼,取代了早期版本的 VBA。32 位和 64 位版本的 Office 2010 中均包含 VBA 7。它提供了兩個條件編譯常量:VBA7 和 Win64。通過測試您的應(yīng)用程序使用的是 VBA 7 還是以前版本的 VBA,VBA7 常量可幫助確保您的代碼的后向兼容性。Win64 常量用于測試代碼是以 32 位還是 64 位形式運行的。下文將介紹這兩個編譯常量。



[url=]ActiveX 控件和 COM 加載項兼容性[/url]

第三方及 Microsoft 提供的現(xiàn)有 32 位 ActiveX 控件與 64 位版本的 Office 2010 不兼容。對于 ActiveX 控件和 COM 對象,有三種可能的解決方案:

  • 如果您有源代碼,則可以自己生成 64 位版本,

  • 您可以與供應(yīng)商聯(lián)系以獲取更新版本,

  • 也可以搜索其他解決方案。




[url=]
[/url]





點擊這里給我發(fā)消息

3#
 樓主| 發(fā)表于 2015-4-18 11:42:21 | 只看該作者
[url=]應(yīng)用程序編程接口兼容性[/url]

VBA 和類型庫的結(jié)合為您提供了許多用于創(chuàng)建 Microsoft Office 應(yīng)用程序的功能。不過,有時,您必須直接與計算機(jī)的操作系統(tǒng)及其他組件進(jìn)行通信,例如在您管理內(nèi)存或進(jìn)程時,在使用用戶界面(例如窗口和控件)時,或在修改 Windows 注冊表時。在這些情況下,最好選擇使用一個嵌入動態(tài)鏈接庫 (DLL) 文件中的外部函數(shù)。為此,可在 VBA 中使用 Declare 語句進(jìn)行 API 調(diào)用。

注釋

Microsoft 提供了一個 Win32API.txt 文件,其中包含 1,500 個 Declare 語句以及一個用于剪切所需 Declare 語句并將其粘貼到您的代碼中的工具。不過,這些語句適用于 32 位系統(tǒng),必須使用下文討論的信息將其轉(zhuǎn)換為 64 位。您可以在 Excel MVP Jan Karel Pieterse 的網(wǎng)站 http://www.jkp-ads.com/articles/apideclarations.asp(該鏈接可能指向英文頁面) 上找到此類型的轉(zhuǎn)換示例。


Declare 語句類似于以下代碼之一,具體取決于您調(diào)用的是子例程(沒有返回值)還是函數(shù)(有返回值)。

[size=1em][url=]VBA[/url]




Public/Private Declare Sub SubName Lib "LibName" Alias "AliasName" (argument list)Public/Private Declare Function FunctionName Lib "Libname" alias "aliasname" (argument list) As Type


SubName 函數(shù)或 FunctionName 函數(shù)會被替換為 DLL 文件中過程的實際名稱,表示在從 VBA 代碼調(diào)用過程時所使用的名稱。如果需要,您還可以為過程名稱指定AliasName 參數(shù)。包含要調(diào)用的過程的 DLL 文件的名稱位于 Lib 關(guān)鍵字之后。最后,參數(shù)列表將包含必須傳遞給該過程的參數(shù)和數(shù)據(jù)類型。

下面的 Declare 語句將打開 Windows 注冊表中的一個子項 并替換其值。

[size=1em][url=]VBA[/url]



Declare Function RegOpenKeyA Lib "advapi32.dll" (ByVal Key As Long, ByVal SubKey As String, NewKey As Long) As Long


RegOpenKeyA 函數(shù)的 Windows.h(窗口句柄)條目如下所示:

[size=1em][url=]VBA[/url]



LONG RegOpenKeyA ( HKEY hKey, LPCSTR lpSubKey, HKEY *phkResult );


在 Microsoft Visual C 和 Microsoft Visual C++ 中,前面的示例對 32 位和 64 位都能夠正確編譯。這是因為 HKEY 定義為指針,其大小反映了在其中編譯代碼的平臺的內(nèi)存大小。

在以前版本的 VBA 中,沒有特定指針數(shù)據(jù)類型,因此使用了 Long 數(shù)據(jù)類型,而 Long 數(shù)據(jù)類型始終為 32 位,所以它在具有 64 位內(nèi)存的系統(tǒng)上使用時會發(fā)生中斷,因為前 32 位可能被截斷或可能覆蓋其他內(nèi)存地址。以上任一情況都會導(dǎo)致不可預(yù)測的行為或系統(tǒng)崩潰。

為解決此問題,VBA 現(xiàn)在包含真正的指針 數(shù)據(jù)類型 LongPtr。此新數(shù)據(jù)類型使您能夠正確編寫原始 Declare 語句,如下所示:

[size=1em][url=]VBA[/url]



Declare PtrSafe Function RegOpenKeyA Lib "advapire32.dll" (ByVal hKey as LongPtr, ByVal lpSubKey As String, phkResult As LongPtr) As Long


此數(shù)據(jù)類型和新的 PtrSafe 屬性使您能夠在 32 位或 64 位系統(tǒng)上使用此 Declare 語句。PtrSafe 屬性向 VBA 編譯器指示 Declare 語句面向 64 位版本的 Office 2010。如果不使用此屬性,那么在 64 位系統(tǒng)中使用 Declare 語句會導(dǎo)致編譯時錯誤。請注意,PtrSafe 屬性在 32 位版本的 Office 2010 上是可選的。因此現(xiàn)有 Declare 語句始終能夠正常運行。

下表提供了有關(guān)已討論過的新限定符和數(shù)據(jù)類型以及另一種數(shù)據(jù)類型、兩個轉(zhuǎn)換運算符和三個函數(shù)的詳細(xì)信息。


類型

說明

限定符

PtrSafe

指示 Declare 語句與 64 位兼容。此屬性在 64 位系統(tǒng)上是必需的。

數(shù)據(jù)類型

LongPtr

一種變量數(shù)據(jù)類型,在 32 位版本的 Office 2010 上是 4 字節(jié)數(shù)據(jù)類型,在 64 位版本上是 8 字節(jié)數(shù)據(jù)類型。這是為新代碼聲明指針或句柄的推薦方法,但如果它必須運行在 64 位版本的 Office 2010 中,則也為舊代碼聲明指針或句柄。只有 32 位和 64 位上的 VBA 7 運行時支持此數(shù)據(jù)類型。請注意,您可以為它賦予數(shù)值,但不能賦予數(shù)值類型。

數(shù)據(jù)類型

LongLong

這是只能在 64 位版本的 Office 2010 中使用的 8 字節(jié)數(shù)據(jù)類型。您可以賦予數(shù)值,但不能賦予數(shù)值類型(以避免截斷)。

轉(zhuǎn)換運算符

CLngPtr

將簡單表達(dá)式轉(zhuǎn)換為 LongPtr 數(shù)據(jù)類型。

轉(zhuǎn)換運算符

CLngLng

將簡單表達(dá)式轉(zhuǎn)換為 LongLong 數(shù)據(jù)類型。

函數(shù)

VarPtr

變量轉(zhuǎn)換器。在 64 位版本上返回 LongPtr,在 32 位版本上返回 Long(4 字節(jié))。

函數(shù)

ObjPtr

對象轉(zhuǎn)換器。在 64 位版本上返回 LongPtr,在 32 位版本上返回 Long(4 字節(jié))。

函數(shù)

StrPtr

字符串轉(zhuǎn)換器。在 64 位版本上返回 LongPtr,在 32 位版本上返回 Long(4 字節(jié))。







點擊這里給我發(fā)消息

4#
 樓主| 發(fā)表于 2015-4-18 11:42:34 | 只看該作者
下面的示例演示如何在 Declare 語句中使用其中某些項。
VBA
Declare PtrSafe Function RegOpenKeyA Lib "advapi32.dll" (ByVal Key As LongPtr, ByVal SubKey As String, NewKey As LongPtr) As Long
請注意,沒有 PtrSafe 屬性的 Declare 語句被假定為與 64 位版本的 Office 2010 不兼容。
如前所述,有兩個新的條件編譯常量:VBA7 和 Win64。為確保與以前版本的 Office 的向后兼容性,可使用 VBA7 常量(這是較典型的情況)來防止 64 位代碼在早期版本的 Office 中運行。對于在 32 位版本和 64 位版本之間有所不同的代碼(例如調(diào)用數(shù)學(xué) API,它對其 64 位版本使用 LongLong,對其 32 位版本使用 Long),可使用 Win64 常量。下面的代碼演示如何使用這兩個常量。
VBA
#if Win64 then
   Declare PtrSafe Function MyMathFunc Lib "User32" (ByVal N As LongLong) As LongLong
#else
   Declare Function MyMathFunc Lib "User32" (ByVal N As Long) As Long
#end if
#if VBA7 then
   Declare PtrSafe Sub MessageBeep Lib "User32" (ByVal N AS Long)
#else
   Declare Sub MessageBeep Lib "User32" (ByVal N AS Long)
#end if
總而言之,如果您編寫 64 位代碼并打算在以前版本的 Microsoft Office 中使用它,則需要使用 VBA7 條件編譯常量。不過,如果您在 Office 2010 中編寫 32 位代碼,則該代碼的工作方式與在以前版本的 Microsoft Office 中一樣,無需使用編譯常量。如果希望確保對 32 位版本使用 32 位語句,對 64 位版本使用 64 位語句,則最好選擇使用Win64 條件編譯常量。
使用條件編譯屬性

下面的代碼是需要更新的舊 VBA 代碼的示例。請注意舊代碼中更新為使用 LongPtr 的數(shù)據(jù)類型,因為它們引用句柄或指針
舊 VBA 代碼
VBA
Declare Function SHBrowseForFolder Lib "shell32.dll" _
  Alias "SHBrowseForFolderA" (lpBrowseInfo As BROWSEINFO) As Long
  
Public Type BROWSEINFO
  hOwner As Long
  pidlRoot As Long
  pszDisplayName As String
  lpszTitle As String
  ulFlags As Long
  lpfn As Long
  lParam As Long
  iImage As Long
End Type
新 VBA 代碼
VBA
#if VBA7 then    ' VBA7
Declare PtrSafe Function SHBrowseForFolder Lib "shell32.dll" _
  Alias "SHBrowseForFolderA" (lpBrowseInfo As BROWSEINFO) As Long

Public Type BROWSEINFO
  hOwner As LongPtr
  pidlRoot As Long
  pszDisplayName As String
  lpszTitle As String
  ulFlags As Long
  lpfn As LongPtr
  lParam As LongPtr
  iImage As Long
End Type

#else    ' Downlevel when using previous version of VBA7

Declare Function SHBrowseForFolder Lib "shell32.dll" _
  Alias "SHBrowseForFolderA" (lpBrowseInfo As BROWSEINFO) As Long

Public Type BROWSEINFO
  hOwner As Long
  pidlRoot As Long
  pszDisplayName As String
  lpszTitle As String
  ulFlags As Long
  lpfn As Long
  lParam As Long
  iImage As Long
End Type

#end if
Sub TestSHBrowseForFolder ()
    Dim bInfo As BROWSEINFO
    Dim pidList As Long

    bInfo.pidlRoot = 0&
    bInfo.ulFlags = &H1
    pidList = SHBrowseForFolder(bInfo)
End Sub
結(jié)論

增加了 64 位版本的 Office 2010 后,您可以移動更多數(shù)據(jù)來增強(qiáng)功能。編寫 32 位代碼時,可以使用 64 位版本的 Microsoft Office 而無需進(jìn)行任何更改。不過,在編寫 64 位代碼時,應(yīng)確保您的代碼包含特定關(guān)鍵字和條件編譯常量,以確保代碼與早期版本的 Microsoft Office 向后兼容,并確保在混合 32 位和 64 位代碼時執(zhí)行了正確的代碼
5#
發(fā)表于 2015-4-20 19:27:53 | 只看該作者
記號
回復(fù)

使用道具 舉報

6#
發(fā)表于 2017-3-17 16:16:56 | 只看該作者
有用。!感謝
回復(fù)

使用道具 舉報

您需要登錄后才可以回帖 登錄 | 注冊

本版積分規(guī)則

QQ|站長郵箱|小黑屋|手機(jī)版|Office中國/Access中國 ( 粵ICP備10043721號-1 )  

GMT+8, 2025-7-13 08:30 , Processed in 0.108455 second(s), 37 queries .

Powered by Discuz! X3.3

© 2001-2017 Comsenz Inc.

快速回復(fù) 返回頂部 返回列表