Copy charts to a new instance of PowerePoint (Jon Poulter version)


Well-known Member
Oct 16, 2008
I have copied verbatim Jons code for:

  1. Opening a new instance of Powerpoint
  2. Copying all charts from a sheet to Powerpoint

this involved placing one piece of code inside another like this, for the sake of clarity I have coloured the code inside and in bold shows where the code trips up

Sub ExcelToNewPowerPoint()
    Dim PPApp As PowerPoint.Application
    Dim PPPres As PowerPoint.Presentation
    Dim PPSlide As PowerPoint.Slide
    Dim PresentationFileName As Variant
    Dim SlideCount As Long
    Dim iCht As Integer
    ' Create instance of PowerPoint
    Set PPApp = CreateObject("Powerpoint.Application")

    ' For automation to work, PowerPoint must be visible
    ' (alternatively, other extraordinary measures must be taken)
    PPApp.Visible = True

    ' Create a presentation
    Set PPPres = PPApp.Presentations.Add

    ' Some PowerPoint actions work best in normal slide view
    PPApp.ActiveWindow.ViewType = ppViewSlide

    ' Add first slide to presentation
    Set PPSlide = PPPres.Slides.Add(1, ppLayoutTitleOnly)

'' Do Some Stuff Here
' Set a VBE reference to Microsoft PowerPoint Object Library

' Reference existing instance of PowerPoint
Set PPApp = GetObject(, "Powerpoint.Application")
' Reference active presentation
Set PPPres = PPApp.ActivePresentation
PPApp.ActiveWindow.ViewType = ppViewSlide

For iCht = 1 To ActiveSheet.ChartObjects.Count
    ' copy chart as a picture
    ActiveSheet.ChartObjects(iCht).Chart.CopyPicture _
        Appearance:=xlScreen, Size:=xlScreen, Format:=xlPicture

    ' Add a new slide and paste in the chart
    SlideCount = PPPres.Slides.Count
    Set PPSlide = PPPres.Slides.Add(SlideCount + 1, ppLayoutBlank)
    PPApp.ActiveWindow.View.GotoSlide PPSlide.SlideIndex
    With PPSlide
        ' paste and select the chart picture
[COLOR="#FF0000"][B]        .Shapes.Paste.Select[/B][/COLOR]
        ' align the chart
        PPApp.ActiveWindow.Selection.ShapeRange.Align msoAlignCenters, True
        PPApp.ActiveWindow.Selection.ShapeRange.Align msoAlignMiddles, True
    End With



' Save and close presentation
    With PPPres
        .SaveAs "C:\My Documents\MyPreso.ppt"
    End With

    ' Quit PowerPoint

    ' Clean up
    Set PPSlide = Nothing
    Set PPPres = Nothing
    Set PPApp = Nothing

End Sub
It runs to the point of pasting the charts but then bombs out with message

Runtime error -2147467259 (80004005)
Automation error
Unspecified error

can anyone suggest what going on, I cant find any help on the error code on line anywhere.


Forum statistics

Latest member

Some videos you may like

This Week's Hot Topics

  • populate from drop list with multiple tables
    Hi All, i have a drop list that displays data, what i want is when i select one of those from the list to populate text from different tables on...
  • Find list of words from sheet2 in sheet1 before a comma and extract text vba
    Hi Friends, Trying to find the solution on my task. But did not find suitable one to the need. Here is my query and sample file with details...
  • Dynamic Formula entry - VBA code sought
    Hello, really hope one of you experts can help with this - i've spent hours on this and getting no-where. .I have a set of data (more rows than...
  • Listbox Header
    Have a named range called "AccidentsHeader" Within my code I have: [CODE]Private Sub CommandButton1_Click() ListBox1.RowSource =...
  • Complex Heat Map using conditional formatting
    Good day excel world. I have a concern. Below link have a list of countries that carries each country unique data. [URL...
  • Conditional formatting
    Hi good morning, hope you can help me please, I have cells P4:P54 and if this cell is equal to 1 then i want row O to say "Fully Utilised" and to...