Excel VBA Copying Duplicate Charts into PPT


Board Regular
May 2, 2015
I'm having a problem with my VBA script... I think.... I must be the code, I can't think of anything else I'm doing wrong.

I've set up my code to copy specific charts into specific slides... however, this is not the case

in Slides 2 & 3 is pastes correctly... then it pastes the chart designated for slide 3 into slides 4-11, then gets back on track and starts putting the charts in correctly again.

Slides 2 & 3 and 12-18 are getting the correct charts, 4-11 are getting the same chart as Slide 3 ("PDA DPU")

Does anyone see anything in my code that is off??

Sub ACOM_Charts()

ActiveSheet.Shapes.Range(Array("Object 10")).Select
Selection.Verb Verb:=3

ActiveWorkbook.SlicerCaches("Slicer_Product_Family").VisibleSlicerItemsList = _
    Array( _
        "[PFs].[Product Family].&[ACOM]")

If Not Application.CalculationState = xlDone Then
End If

Application.Wait (Now + TimeValue("00:00:05")) '[COLOR=#0000ff]After the slicer selection, the data takes time to load, so I was hoping adding this would give it time to load the charts with the correct info[/COLOR]'

Dim myPresentation As Object
Dim mySlide As Object
Dim PowerPointApp As Object
Dim shp As Object
Dim MySlideArray As Variant
Dim MyChartArray As Variant
Dim HeatMap As String
Dim X As Long

On Error Resume Next
Set PowerPointApp = GetObject(class:="PowerPoint.Application")

If PowerPointApp Is Nothing Then
    MsgBox "PowerPoint Presentation is not open, action aborted."
Exit Sub
End If
If Err.Number = 429 Then
    MsgBox "PowerPoint could not be found, action aborted."
Exit Sub
End If

On Error GoTo 0
Set myPresentation = PowerPointApp.ActivePresentation

[COLOR=#008000]'List of PPT Slides to Paste to[/COLOR]
MySlideArray = Array(2, 3, 7, 6, 11, 4, 5, 10, 9, 8, 16, 17, 12, 13, 14, 15, 18)

[COLOR=#008000]'List of Excel Ranges to Copy from[/COLOR]
MyChartArray = Array(Sheet1.ChartObjects("PDI DPU"), Sheet1.ChartObjects("PDA DPU"), Sheet1.ChartObjects("Stop Time"), Sheet1.ChartObjects("Velocity Events"), Sheet1.ChartObjects("MFN"), Sheet2.ChartObjects("ACOM Assy PDI DPU"), Sheet2.ChartObjects("ACOM Assy PDA DPU"), Sheet2.ChartObjects("Assy Caused PU"), Sheet2.ChartObjects("Assy Repair CG"), Sheet2.ChartObjects("Stop Time PU by CG"), Sheet3.ChartObjects("RTY"), Sheet3.ChartObjects("RTY FPY"), Sheet4.ChartObjects("300 DF"), Sheet4.ChartObjects("350 DF"), Sheet4.ChartObjects("400 DF"), Sheet4.ChartObjects("500 DF"), Sheet5.ChartObjects("Assigned Events"))

[COLOR=#008000]'Loop through Array data[/COLOR]
  Application.DisplayAlerts = False
  For X = LBound(MySlideArray) To UBound(MySlideArray)
    'Copy Excel Range
[COLOR=#008000]    'Paste to PowerPoint and position[/COLOR]
      On Error Resume Next
        Set shp = myPresentation.Slides(MySlideArray(X)).Shapes.Paste  'Excel 2007-2010
        Set shp = PowerPointApp.ActiveWindow.Selection.ShapeRange 'Excel 2013
      On Error GoTo 0
[COLOR=#008000]    'Center Object[/COLOR]
      With myPresentation.PageSetup
        On Error Resume Next
      End With
  Next X
  Application.DisplayAlerts = True
[COLOR=#008000]'Transfer Complete[/COLOR]
  Application.CutCopyMode = False
  MsgBox "Export to PowerPoint complete. Note: The slides will be lost when this workbook is closed. Make sure to print the slides and/or save a copy before closing this workbook."

End Sub

Forum statistics

Latest member

Some videos you may like

This Week's Hot Topics