且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

将图表从Excel复制到PowerPoint的脚本中的错误

更新时间:2023-02-15 11:02:13

在最新版本的Office中,我遇到了很多麻烦. 2003年及更早版本没有此问题,2007年和2010年则有此问题,而2013年和2016年则有此问题.

I have had a lot of trouble in recent versions of Office. 2003 and earlier didn't have this problem, 2007 and 2010 had it a bit, and 2013 and 2016 have it in spades.

单步执行代码时,它可以正常工作,但是当全速运行时,它会在粘贴时出错.

When you step through the code it works fine, but when you run it at full speed, it errors on the paste.

这似乎是没有时间完成复制,因此在粘贴剪贴板时还没有要粘贴的内容.

It's as if the copy doesn't have time to finish finish, so when you paste the clipboard doesn't have anything in it yet to paste.

有时候这会有所帮助:

chrt.CopyPicture Appearance:=xlScreen, Format:=xlBitmap
DoEvents
curSlide.Shapes.Paste

DoEvents告诉VBA等待后台操作有机会完成.

DoEvents tells VBA to wait while background operations have a chance to finish up.