Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Error with copy/paste in excel 2010 VBA when trying to insert charts, ranges etc into word

Tags:

excel

vba

In researching this error I've come to the conclusion that it has to do with the clipboard not clearing like it should which wasn't an issue when we were using 2003 but is now that we are using 2010. (I also inherited this code from someone who doesn't work here anymore)

Run-Time error "4605":
This method or property is not available because the clipboard is empty or not valid.

This is my code:

Worksheets("Exec Sum").Range("B140:I186").Copy

With myDoc.Bookmarks
  .Item("b3").Range.PasteSpecial Link:=True, DataType:=wdPasteMetafilePicture, Placement:=bmark, DisplayAsIcon:=False
End With

' Clears Clipboard
Application.CutCopyMode = False

I've tried sendkeys ("^C") with selecting an empty cell first but no luck. Is there any way that I could either not use the copy/paste method to do this or a different way to clear the clipboard?

like image 895
Gravity Kills Avatar asked Aug 22 '12 16:08

Gravity Kills


1 Answers

I started getting this error when I upgraded from 2003 to 2010, but the macro still worked in 2003.

The tables were there, but I noticed that sometimes the copying didn't work. As this didn't ever happen in debug mode, I added 5 secs waiting time right before the copying.

This makes the macro slower, but at least it works.

like image 164
scott Avatar answered Sep 23 '22 20:09

scott