将resize的图片从Excel导出到PowerPoint 2010
我创build了一个将图片从Excel复制到新的PowerPoint演示文稿的代码。 该代码适用于MS Office 2016,但不是 MS Office 2010.特别是,导出到PowerPoint的图片不会在2010年的.pptx
resize。
我怎样才能解决这个问题?
以下是在MS 2010中不起作用的有问题的代码片段:
Application.Goto Reference:="Full_Account_Performance" Application.CutCopyMode = False Selection.CopyPicture Appearance:=xlScreen, Format:=xlPicture PPPres.Slides(x).Shapes.PasteSpecial On Error Resume Next With PPApp.ActiveWindow.Selection.ShapeRange .ScaleHeight 0.435, msoFalse, msoScaleFromTopLeft 'Powerpoint 2010 ingnors it... but in 2016 it is fine .Left = 10 .Top = 55 End With
在PowerPoint 2010中,在使用Shapes.PasteSpecial
命令粘贴图片后,它有时会跳过这些行(它们不会被跳过,只是代码在完成之前运行它们来粘贴图片)。
有一个解决办法,你可以添加一个延迟一秒,代码将工作(下面的行将不会被跳过)。
下面的代码将在PowerPoint中将Object
设置为粘贴图片,稍后修改myShape
属性。
注意 :下面的代码使用了Late Binding ,但它也可以用于Early Binding 。
码
Dim PPPres As Object Dim PPSlide As Object Dim myShape As Object ' set the slide object - x is the slide number Set PPSlide = PPPres.Slides(x) ' Set an Object to the Pasted PowerPoint picture Set myShape = PPSlide.Shapes.PasteSpecial(0, msoFalse) ' ppPasteDefault = 0 With myShape ' it skips the lines below, add a delay Application.Wait Now + TimeValue("00:00:01") .ScaleHeight 0.435, msoFalse, msoScaleFromTopLeft .Left = 10 .Top = 55 End With
这似乎是问题:
With PPApp.ActiveWindow.Selection.ShapeRange
尝试:
With PPPres.Slides(x).Shapes(y)
其中y =你刚刚粘贴的图片。 由于您没有设置对它的引用,因此您可能需要遍历幻灯片中的形状来查找它是哪个形状。