Home » excel » Clear clipboard when copying graphs in Excel VBA

Clear clipboard when copying graphs in Excel VBA

Posted by: admin May 14, 2020 Leave a comment


I copy and paste several Excel graphs from Excel to Powerpoint using VBA:

'copy from excel worksheet
    Workbooks(Stats & ".xls").Worksheets(Stats).ChartObjects("graph4").Copy
'paste into powerpoint presentation

' more code and more copy and pastes
' ...

Sometimes, copying the graphs fails. I have no explanation for this other than maybe memory problems.
The error message that I get:

Method ‘Copy’ of object ‘Chartobject’ failed.

Then Excel gets unresponsive and I have to restart it.

What can I do to prevent this?
Maybe I could clear the clipboard between the copy and paste operations?

I’ve tried the two mentioned ways to clear the clipboard. The copy & paste operation still fails from time to time. The run-time error is “-2147417848 (80010108)”.
There’s some info about this error on the net, so I’ll start over from there.

Update (Final):
I think I solved the problem by putting this code in front of the parts where the charts are copy and pasted. The error has not appeared again.

DoEvents 'lets the operating system clear / execute any backed up / queued events that it might have to execute.
'slow down the execution (to not get an error)
Workbooks(Stats & ".xls").Save
How to&Answers:

Trying putting Application.CutCopyMode = 0 between the copy and paste operations.

0 or False means “Cancels Cut or Copy mode and removes the moving border”:


Here is a small example for accessing the clipboard by VBA:


Clear the clipboard by putting some empty text into it. Honestly, I don’t know if this will solve your original problem.


You don’t mention which version of Office you’re working in. If 2007, have you applied Service Pack 2 and checked for hotfixes that might address this issue?

The original release of 2007 was awful.


I was unsuccessful with inserting
application.cutcopymode = 0
between copy and paste statements.

I was successful when I inserted
application.cutcopymode = 0
between the paste and close statements.

windows(ThisBook).activate: range(nextcell).select: activesheet.paste
application.cutcopymode = 0
windows(OtherBook).activate: activewindow.close


Activate the object before you paste. I solved using the following