Can't clear office clipboard with VBA

DasPete picture DasPete · Jan 21, 2013 · Viewed 9k times · Source

I am using a function to copy a bunch of pictures out of an access database and store them on to the disk. However, this function uses the office clipboard and the clipboard fills up after about 150 records and crashes the program. Here is how I am clearing 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

Anyone know how to more effectively clear the clipboard

Answer

SeanC picture SeanC · Jan 21, 2013

The functions you are using refer to the windows clipboard. This is different to the Office Clipboard

The only code I've found to clear that clipboard is Application.CommandBars("Clipboard").Controls(4).Execute, but as I have the office clipboard disabled (and, apparently, no way of enabling it), I can't see if that is the actual solution