I have copied verbatim Jons code for:
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
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.
Martin
- Opening a new instance of Powerpoint
- 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
Code:
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)
[COLOR="#0000CD"]''---------------------
'' 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
Next
''---------------------[/COLOR]
' Save and close presentation
With PPPres
.SaveAs "C:\My Documents\MyPreso.ppt"
.Close
End With
' Quit PowerPoint
PPApp.Quit
' Clean up
Set PPSlide = Nothing
Set PPPres = Nothing
Set PPApp = Nothing
End Sub
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.
Martin