WendyLou315
New Member
- Joined
- Nov 19, 2014
- Messages
- 13
Programing a procedure which opens a .ppt template and copies in charts and tables from Excel for multiple generation of presentations (a Do Loop) for a new .ppt per record on a specific worksheet. What appears to be an every-other-time/record event, the pasting of an Excel chart is interrupted mid-process by closing PowerPoint after entering a WITH statement to place and size the chart on the first one of the WITH statement which is selecting the shape number of the chart just added (therefore before the procedure performs the PPT.Quit). Naturally the program cannot find the presentation to format the shape on the slide and all other work conducted in the PowerPoint presentation has been lost.
Here is a condensed version of the procedure but I CAN provide the whole thing. There are two tables copied to the PowerPoint which seem to have no issues with being added. To be clear: it works for the first record of the Excel worksheet, but the second ALWAYS fails and closes the .ppt before it can format the chart just copied to the slide.
Here is a condensed version of the procedure but I CAN provide the whole thing. There are two tables copied to the PowerPoint which seem to have no issues with being added. To be clear: it works for the first record of the Excel worksheet, but the second ALWAYS fails and closes the .ppt before it can format the chart just copied to the slide.
Code:
'Slide 8 = Contour Overlay Chart
Sheets("Contour Plot").Select
'Copy Chart into PowerPoint
ActiveSheet.ChartObjects("ContourPlot").Activate
ActiveSheet.ChartObjects("ContourPlot").Activate
ActiveSheet.ChartObjects("ContourPlot").Chart.CopyPicture _
appearance:=xlScreen, Size:=xlScreen, Format:=xlPicture
PPT.ActivePresentation.Slides(8).Shapes.PasteSpecial Link:=0
NumShape = PPT.ActivePresentation.Slides(8).Shapes.Count
With PPT.ActivePresentation.Slides(8).Shapes(NumShape) 'Here is where it closes .ppt every OTHER instance from a loop before it gets to the next line
.Height = 390
.Left = 160
.Top = 110
End With
Application.CutCopyMode = False
'Save and Close the PowerPoint presentation
PPT.ActivePresentation.Save
PPT.ActivePresentation.Close
'Stop the PowerPoint connection
PPT.Quit
'Clear the memory
Set PPT = Nothing
Last edited: