(Solved) – VBA Unable to copy chart on specific worksheet to PowerPoint

  • by

I have multiple sheets with charts but I would like to copy charts from “Calculated Sheets” only, but my code is failing. If I don’t put the ("Calculated Sheets"), the macro copies all the charts. Thanks for the help.

Dim ppt As PowerPoint.Application
Dim ppTPres As PowerPoint.Presentation
Dim pptSld As PowerPoint.Slide
Dim pptCL As PowerPoint.CustomLayout
Dim pptShp As PowerPoint.Shape

Dim chtt As Chart
Dim ws As Worksheet
Dim i As Long

'Optimise execution of code
Application.ScreenUpdating = False

'Get the PowerPoint Application object:
Set ppt = CreateObject("PowerPoint.Application")
ppt.Visible = msoTrue
Set ppTPres = ppt.Presentations.Add

'Get a Custom Layout:
For Each pptCL In ppTPres.SlideMaster.CustomLayouts
    If pptCL.Name = "Title and Content" Then Exit For
Next pptCL

For Each ws In ActiveWorkbook.Worksheets("Calculated Values")
    For i = 1 To ws.ChartObjects.Count
        Set pptSld = ppTPres.Slides.AddSlide(ppTPres.Slides.Count   1, pptCL)

        For Each pptShp In pptSld.Shapes.Placeholders
            If pptShp.PlaceholderFormat.Type = ppPlaceholderObject Then Exit For
        Next pptShp

        Set chtt = ws.ChartObjects(i).Chart

          Next i
           Next ws

Leave a Reply

Your email address will not be published. Required fields are marked *