2013-01-21 157 views
4

我正在使用一種功能將大量圖片從訪問數據庫中複製出來並存儲到磁盤上。但是,此功能使用辦公室剪貼板和剪貼板填滿大約150條記錄並使程序崩潰。這裏是我正在清除剪貼板無法使用VBA清除辦公室剪貼板

Private Declare Function apiOpenClipboard Lib "user32" Alias "OpenClipboard" (ByVal hwnd As Long) As Long 
Private Declare Function apiEmptyClipboard Lib "user32" Alias "EmptyClipboard"() As Long 
Private Declare Function apiCloseClipboard Lib "user32" Alias "CloseClipboard"() As Long 

Sub EmptyClipboard() 
    Call apiOpenClipboard(0&) 
    Call apiEmptyClipboard 
    Call apiCloseClipboard 
End Sub 

任何人都知道如何更有效地清除剪貼板

+0

根據什麼版本,這可能工作:Application.CutCopyMode = False – PinkElephantsOnParade

+0

謝謝,我試過了,它似乎沒有任何幫助。我正在使用office 2010 – DasPete

+0

您已將您的問題標記爲'ms-access-2007',可能要更新標記以獲得更好/正確的知名度 – LittleBobbyTables

回答

1

您使用的是指到Windows剪貼板的功能。這是Office Clipboard

我發現清除剪貼板的唯一代碼是Application.CommandBars("Clipboard").Controls(4).Execute,但由於我禁用了辦公剪貼板(顯然無法啓用它),所以我無法看到是否這是實際的解決方案

+0

謝謝我給了一個嘗試,但訪問似乎並不喜歡它太多,「下標超出範圍」我發現,如果我保持剪貼板面板打開,我可以點擊「全部清除」按鈕,而我的程序循環通過記錄。這似乎是最好的解決方案。這不是理想的,但它的工作原理。謝謝大家的幫助! – DasPete

0

我已閱讀elsewhere,這將你需要的東西:

Option Explicit 

Public Sub ClearClipBoard() 
    Dim oData As New DataObject 'object to use the clipboard 

    oData.SetText Text:=Empty 'Clear 
    oData.PutInClipboard 'take in the clipboard to empty it 
End Sub 
+0

這也適用於Windows剪貼板,不適用於Office剪貼板。 – Andre

0

嘗試: (舊線,我知道;-))

Private Declare Function AccessibleChildren Lib "oleacc" (ByVal paccContainer As Office.IAccessible, ByVal iChildStart As Long, ByVal cChildren As Long, ByRef rgvarChildren As Any, ByRef pcObtained As Long) As Long 
    'by E v R 
Sub ClearOfficeClipBoard() 
Dim Acc As Office.IAccessible 

    With Application 
     .CommandBars("Office Clipboard").Visible = True 
    DoEvents 
     Set Acc = .CommandBars("Office Clipboard").accChild(1) 
     Set Acc = zetAcc(Acc, 3) 
     Set Acc = zetAcc(Acc, 0) 
     Set Acc = zetAcc(Acc, 3) 
     Acc.accDoDefaultAction 2& 
     .CommandBars("Office Clipboard").Visible = False 
    End With 

End Sub 
Private Function zetAcc(myAcc As Office.IAccessible, myChildIndex As Long) As Office.IAccessible 
Dim ReturnAcc As Office.IAccessible 
Dim Count As Long, List() As Variant 

    Count = myAcc.accChildCount 
    ReDim List(Count - 1&) 
    If AccessibleChildren(myAcc, 0&, ByVal Count, List(0), Count) = 0& Then Set zetAcc = List(myChildIndex) 

End Function