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

  • by
(solved)-–-vba-unable-to-copy-chart-on-specific-worksheet-to-powerpoint

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)
        pptSld.Select

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

        Set chtt = ws.ChartObjects(i).Chart
        chtt.ChartArea.Copy
        ppt.Activate
        pptShp.Select
        ppt.Windows(1).View.Paste

          Next i
           Next ws

Leave a Reply

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