Cannot clear clipboard using VBA

I use the function to copy a bunch of images from the access database and save them to disk. However, this function uses the clipboard in the office, and the clipboard fills up after about 150 entries and displays a program failure message. This is how I clear the clipboard

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 

Does anyone know how to clean the clipboard more efficiently

+4
source share
3 answers

The functions you use are related to the window buffer. This is different from Office Clipboard.

The only code I found to clear the Application.CommandBars("Clipboard").Controls(4).Execute , but since I have the clipboard disabled (and apparently there is no way to enable it), I don’t see whether this is an actual solution

+1
source

I read elsewhere that this will do what you need:

 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
source

Try: (old topic, I know ;-))

 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 
0
source

All Articles