将图表从Excel复制到PowerPoint的脚本中的错误 [英] Error in script which copies charts from Excel to PowerPoint

查看:82
本文介绍了将图表从Excel复制到PowerPoint的脚本中的错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图调用下面的Sub,以便将给定的图表复制到指定的PowerPoint演示文稿中.但是,当我运行调用此Sub的宏时,下面指示的行返回以下错误:对象不支持此属性或方法."奇怪的是Shape和Slide都包含被称为的方法.同样,位图已正确复制到我的剪贴板 中,并在调用错误之前粘贴到幻灯片中.您将在下面找到Sub().

I am attempting to call the below Sub in order to copy given chart to a specified PowerPoint presentation. However, when I run the macro which calls this Sub, the line indicated below returns the following error: "Object doesn't support this property or method." What's odd is that both Shapes and Slide do contain the methods which are called. As well, the bitmap is correctly copied to my clipboard and pastes into the slide before the error is called. You will find the Sub() below.

Sub copyChart(chrt As Chart, pres As PowerPoint.Presentation)
    Dim curSlide As Slide, dummySlide As Slide
    Set dummySlide= pres.Slides(2) 'Second slide is dummy slide.
    Set curSlide = dummySlide.Duplicate(1) 'Duplicate dummy, set as current slide.
    chrt.CopyPicture Appearance:=xlScreen, Format:=xlBitmap 'Copy the chart as a picture.
    curSlide.Shapes.Paste '<-----------Error here.
End Sub

我也希望提供整个脚本的.txt文件,但不确定如何(在此处粘贴有点长).感谢您的帮助.

As well, I was hoping to provide a .txt file of my entire script, but was unsure how (it is a little lengthy to paste here). Thanks for your help.

(请注意,此实现与将Excel图表粘贴到使用VBA的Powerpoint ,使我更加困惑.)

(Note that this implementation is very similar to that at Paste Excel Chart into Powerpoint using VBA, further confusing me.)

推荐答案

在最新版本的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.

这篇关于将图表从Excel复制到PowerPoint的脚本中的错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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