Access從剪切版里復制和粘貼數(shù)據(jù)
時間:2013-11-14 17:47 來源:office中國 作者:tmtony 閱讀:次
我們所說的剪切板是指windows 操作系統(tǒng)提供的一個暫存數(shù)據(jù)的地方,并且提供共享的一個模塊,也稱為數(shù)據(jù)中轉(zhuǎn)站。
當新的內(nèi)容復制到剪切板后,會把舊內(nèi)容覆蓋。 單擊“開始”,單擊“運行”,然后鍵入 “clipbrd”命令即可啟動“剪貼薄查看器”小工具
下面的函數(shù)能復制和粘貼剪切板中的數(shù)據(jù)。
當新的內(nèi)容復制到剪切板后,會把舊內(nèi)容覆蓋。 單擊“開始”,單擊“運行”,然后鍵入 “clipbrd”命令即可啟動“剪貼薄查看器”小工具
下面的函數(shù)能復制和粘貼剪切板中的數(shù)據(jù)。
Declare Function abOpenClipboard Lib "User32" Alias "OpenClipboard" (ByVal Hwnd As Long) As Long
Declare Function abCloseClipboard Lib "User32" Alias "CloseClipboard" () As Long
Declare Function abEmptyClipboard Lib "User32" Alias "EmptyClipboard" () As Long
Declare Function abIsClipboardFormatAvailable Lib "User32" Alias "IsClipboardFormatAvailable" (ByVal wFormat As Long) As Long
Declare Function abSetClipboardData Lib "User32" Alias "SetClipboardData" (ByVal wFormat As Long, ByVal hMem As Long) As Long
Declare Function abGetClipboardData Lib "User32" Alias "GetClipboardData" (ByVal wFormat As Long) As Long
Declare Function abGlobalAlloc Lib "Kernel32" Alias "GlobalAlloc" (ByVal wFlags As Long, ByVal dwBytes As Long) As Long
Declare Function abGlobalLock Lib "Kernel32" Alias "GlobalLock" (ByVal hMem As Long) As Long
Declare Function abGlobalUnlock Lib "Kernel32" Alias "GlobalUnlock" (ByVal hMem As Long) As Boolean
Declare Function abLstrcpy Lib "Kernel32" Alias "lstrcpyA" (ByVal lpString1 As Any, ByVal lpString2 As Any) As Long
Declare Function abGlobalFree Lib "Kernel32" Alias "GlobalFree" (ByVal hMem As Long) As Long
Declare Function abGlobalSize Lib "Kernel32" Alias "GlobalSize" (ByVal hMem As Long) As Long
Const GHND = &H42
Const CF_TEXT = 1
Const APINULL = 0To copy to the clipboard:
'復制到粘貼表
Function Text2Clipboard(szText As String)
Dim wLen As Integer
Dim hMemory As Long
Dim lpMemory As Long
Dim retval As Variant
Dim wFreeMemory As Boolean
' Get the length, including one extra for a CHR$(0) at the end.
wLen = Len(szText) + 1
szText = szText & Chr$(0)
hMemory = abGlobalAlloc(GHND, wLen + 1)
If hMemory = APINULL Then
MsgBox "Unable to allocate memory."
Exit Function
End If
wFreeMemory = True
lpMemory = abGlobalLock(hMemory)
If lpMemory = APINULL Then
MsgBox "Unable to lock memory."
GoTo T2CB_Free
End If
' Copy our string into the locked memory.
retval = abLstrcpy(lpMemory, szText)
' Don't send clipboard locked memory.
retval = abGlobalUnlock(hMemory)
If abOpenClipboard(0&) = APINULL Then
MsgBox "Unable to open Clipboard. Perhaps some other application is using it."
GoTo T2CB_Free
End If
If abEmptyClipboard() = APINULL Then
MsgBox "Unable to empty the clipboard."
GoTo T2CB_Close
End If
If abSetClipboardData(CF_TEXT, hMemory) = APINULL Then
MsgBox "Unable to set the clipboard data."
GoTo T2CB_Close
End If
wFreeMemory = False
T2CB_Close:
If abCloseClipboard() = APINULL Then
MsgBox "Unable to close the Clipboard."
End If
If wFreeMemory Then GoTo T2CB_Free
Exit Function
T2CB_Free:
If abGlobalFree(hMemory) <> APINULL Then
MsgBox "Unable to free global memory."
End If
End Function
'從剪切板粘貼:
Function Clipboard2Text()
Dim wLen As Integer
Dim hMemory As Long
Dim hMyMemory As Long
Dim lpMemory As Long
Dim lpMyMemory As Long
Dim retval As Variant
Dim wFreeMemory As Boolean
Dim wClipAvail As Integer
Dim szText As String
Dim wSize As Long
If abIsClipboardFormatAvailable(CF_TEXT) = APINULL Then
Clipboard2Text = Null
Exit Function
End If
If abOpenClipboard(0&) = APINULL Then
MsgBox "Unable to open Clipboard. Perhaps some other application is using it."
GoTo CB2T_Free
End If
hMemory = abGetClipboardData(CF_TEXT)
If hMemory = APINULL Then
MsgBox "Unable to retrieve text from the Clipboard."
Exit Function
End If
wSize = abGlobalSize(hMemory)
szText = Space(wSize)
wFreeMemory = True
lpMemory = abGlobalLock(hMemory)
If lpMemory = APINULL Then
MsgBox "Unable to lock clipboard memory."
GoTo CB2T_Free
End If
' Copy our string into the locked memory.
retval = abLstrcpy(szText, lpMemory)
' Get rid of trailing stuff.
szText = Trim(szText)
' Get rid of trailing 0.
Clipboard2Text = Left(szText, Len(szText) - 1)
wFreeMemory = False
CB2T_Close:
If abCloseClipboard() = APINULL Then
MsgBox "Unable to close the Clipboard."
End If
If wFreeMemory Then GoTo CB2T_Free
Exit Function
CB2T_Free:
If abGlobalFree(hMemory) <> APINULL Then
MsgBox "Unable to free global clipboard memory."
End If
End Function
(責任編輯:admin)
頂一下
(1)
100%
踩一下
(0)
0%
相關(guān)內(nèi)容
- ·API函數(shù)詳細解釋
- ·Access從剪切版里復制和粘貼數(shù)據(jù)
- ·Access利用api實現(xiàn)打開/關(guān)閉光驅(qū)
- ·應用程序開機自動啟動(注冊表操作技巧
- ·Access VBA 判斷網(wǎng)絡(luò)是否連通的多種辦
- ·什么是ADP,了解ADP的優(yōu)缺點
- ·優(yōu)秀產(chǎn)品大全--通用票據(jù)打印軟件(新)
- ·[技巧分享]多條Shell語句執(zhí)行導致判斷
- ·在access中可以調(diào)用API函數(shù)GetFileInfo
- ·Access API集中營--增加臨時使用的字體
- ·API ShellExecute 功能說明及應用示例
- ·在VB中使用API函數(shù)(什么是API? )
- ·API實現(xiàn)完美的圖片出現(xiàn)效果(轉(zhuǎn))
- ·API 設(shè)置調(diào)整系統(tǒng)當前時間
- ·如何檢測以及設(shè)置鍵盤狀態(tài)
- ·不關(guān)閉當前數(shù)據(jù)庫COPY當前數(shù)據(jù)庫
最新內(nèi)容
- ·API函數(shù)詳細解釋
- ·Access從剪切版里復制和粘貼數(shù)據(jù)
- ·Access利用api實現(xiàn)打開/關(guān)閉光驅(qū)
- ·應用程序開機自動啟動(注冊表操作技巧)
- ·Access VBA 判斷網(wǎng)絡(luò)是否連通的多種辦法(函
- ·什么是ADP,了解ADP的優(yōu)缺點
- ·優(yōu)秀產(chǎn)品大全--通用票據(jù)打印軟件(新)
- ·[技巧分享]多條Shell語句執(zhí)行導致判斷出錯
- ·在access中可以調(diào)用API函數(shù)GetFileInformat
- ·Access API集中營--增加臨時使用的字體
推薦內(nèi)容