I've created a code that copies pictures from Excel to a new PowerPoint presentation. The code works fine for MS Office 2016, but not MS Office 2010. Particularly, a picture that is exported to PowerPoint will not be resized in .pptx
for 2010.
How can I fix this?
Here is the problematic piece of code that does not work in 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
In PowerPoint 2010, it sometimes skips the lines after you paste a picture using Shapes.PasteSpecial
command (they are not skipped, just the code runs them before it completes to paste the Picture).
There is a work-around, you can add a delay of a second, and the code will work (the lines below won't be skipped).
The code below will set an Object
to the pasted picture in PowerPoint, and later just modify myShape
properties.
Note: The code below uses Late Binding, but it will work also for Early Binding.
Code
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