Excel VBA Copying Duplicate Charts into PPT

Sphinx404

Board Regular
Joined
May 2, 2015
Messages
186
Office Version
  1. 365
Platform
  1. Windows
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??

Code:
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
    DoEvents
End If
  
Application.CalculateUntilAsyncQueriesDone


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")
    
Err.Clear


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
  
PowerPointApp.ActiveWindow.Panes(2).Activate
    
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
        MyChartArray(X).Copy
    
[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
        shp.LinkFormat.BreakLink
      End With
   
  Next X
  Application.DisplayAlerts = True
[COLOR=#008000]'Transfer Complete[/COLOR]
  Application.CutCopyMode = False
  ThisWorkbook.Activate
  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
 

Excel Facts

Workdays for a market open Mon, Wed, Friday?
Yes! Use "0101011" for the weekend argument in NETWORKDAYS.INTL or WORKDAY.INTL. The 7 digits start on Monday. 1 means it is a weekend.

Forum statistics

Threads
1,224,823
Messages
6,181,179
Members
453,021
Latest member
Justyna P

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top