尝试在Word中插入图表,范围等时,在Excel 2010 VBA中复制/粘贴时出错 [英] Error with copy/paste in excel 2010 VBA when trying to insert charts, ranges etc into word

查看:163
本文介绍了尝试在Word中插入图表,范围等时,在Excel 2010 VBA中复制/粘贴时出错的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在研究此错误时,我得出的结论是,它与剪贴板清除不当有关,这在我们使用2003时不是问题,但现在我们在使用2010年.(我也从不再在这里工作的人那里继承了此代码)

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)

运行时错误"4605":
此方法或属性不可用,因为剪贴板为空或无效.

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

这是我的代码:

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

我尝试过先选择一个空单元格但没有运气的sendkeys("^ C").有什么方法不能使用复制/粘贴方法来执行此操作,也不能以其他方式清除剪贴板吗?

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?

推荐答案

从2003年升级到2010年时,我开始收到此错误,但是该宏在2003年仍然有效.

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

桌子在那儿,但我注意到有时无法进行复制.由于在调试模式下从未发生过这种情况,因此我在复制之前增加了5秒的等待时间.

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.

这篇关于尝试在Word中插入图表,范围等时,在Excel 2010 VBA中复制/粘贴时出错的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆