在Excel VBA中复制图形时,清除剪贴板 [英] Clear clipboard when copying graphs in Excel VBA

查看:800
本文介绍了在Excel VBA中复制图形时,清除剪贴板的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用VBA将Excel中的几个Excel图形复制并粘贴到Powerpoint上:

 '从excel工作表复制
工作簿(Stats&.xls)。工作表(统计).ChartObjects(graph4)。将
'粘贴到PowerPoint中。
.Slides(3).Shapes.Paste

'更多的代码和更多的副本和粘贴
'...

有时,复制图表失败。我没有解释这可能是记忆问题。
我得到的错误消息:


方法'复制'对象'Chartobject'失败。


然后Excel无响应,我必须重新启动。



我可以做什么来防止这个?
也许我可以在复制和粘贴操作之间清除剪贴板?



更新:
我已经尝试了两种提到的方法来清除剪贴板。副本&粘贴操作不时会失败。运行时错误为-2147417848(80010108)。
有一些关于这个错误在网上的信息,所以我将从那里重新开始。



更新(最终):
我认为我将此代码放在图表复制和粘贴的部分的前面解决了这个问题。该错误没有再次出现。

  DoEvents'允许操作系统清除/执行任何备份或排队的事件执行。 
'减慢执行(不能得到错误)
工作簿(Stats&.xls)。保存


解决方案

尝试在复制和粘贴操作之间放置 Application.CutCopyMode = 0 p>

0 False 表示取消剪切或复制模式删除移动边框:
http://msdn.microsoft .com / en-us / library / office / ff839532.aspx


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
    .Slides(3).Shapes.Paste

' 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?

Update: 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

解决方案

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": http://msdn.microsoft.com/en-us/library/office/ff839532.aspx

这篇关于在Excel VBA中复制图形时,清除剪贴板的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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