Creating Powerpoint presentations automatically is handy if you want the power to control another office application. In this post I will copy a chart in Excel and paste it into a fresh instance of Power Point. I will show two examples, once where the data will be pasted into a presentation with a title and one without. This is a building blocks approach, creating a procedure which pastes one chart might seem like time better spent done manually but if there were 20 charts it would be faster for VBA to do the work for you. It could cut down error as well, the more laborious a task the more likely you are to miss a chart or copy the same chart twice. Excel take the manual part of that process out of the equation and only puts in the charts from a particular sheet or workbook.
One of the things you will need to remember when you commence this task is to create a link to the Powerpoint object library.
On the Tools Menu choose Reference.
Click on the Microsoft Powerpoint xx.0 object library. Then click OK.
This will allow Excel and Powerpoint to talk to one another. The following is the coding which will achieve the task.
Option Explicit
Sub CopyChartPP()
Dim oPPT As Object
Dim oPres As Object
Dim oSld As Object
Dim oWS As Worksheet
Dim oCHT As ChartObject
Set oPPT = CreateObject("PowerPoint.Application")
Set oPres = oPPT.Presentations.Add(msoTrue)
Set oSld = oPres.Slides.Add(1, ppLayoutTitleOnly)
Set oWS = ActiveWorkbook.Worksheets(1)
Set oCHT = oWS.ChartObjects(1)
oCHT.Select
ActiveChart.ChartArea.Copy
oSld.Shapes.PasteSpecial link:=msoTrue
End Sub
In order to put the single chart into a blank PowerPoint slide change the line above:
I will post a file shortly.