Export Excel Charts to PowerPoint
Here is the code to export all charts in a sheet to powerpoint. Just pass the worksheet object as function parameter and it will export all charts in it onto Powerpoint. Alternatively, you can also download the attached file and see how the code works.
Option Explicit Function getPPPres() As PowerPoint.Presentation Dim PPApp As PowerPoint.Application 'Reference instance of PowerPoint On Error Resume Next 'Check whether PowerPoint is running Set PPApp = GetObject(, "PowerPoint.Application") If PPApp Is Nothing Then 'PowerPoint is not running, create new instance Set PPApp = CreateObject("PowerPoint.Application") 'For automation to work, PowerPoint must be visible PPApp.Visible = True End If On Error GoTo 0 'Reference presentation and slide On Error Resume Next If PPApp.Windows.Count > 0 Then 'There is at least one presentation 'Use existing presentation Set getPPPres = PPApp.ActivePresentation Else 'There are no presentations 'Create New Presentation Set getPPPres = PPApp.Presentations.Add End If Set PPApp = Nothing End Function Function getNewSlide(PPPres As PowerPoint.Presentation) As PowerPoint.Slide Set getNewSlide = PPPres.Slides.Add(PPPres.Slides.Count + 1, ppLayoutBlank) End Function Sub ExportChartsToPPT(wksChartsFromSheet As Worksheet) Dim PPPres As PowerPoint.Presentation Dim PPSlide As PowerPoint.Slide Dim cht As ChartObject If wksChartsFromSheet.ChartObjects.Count = 0 Then MsgBox "No Chart to Export to Powerpoint", vbInformation, "" Exit Sub End If Set PPPres = getPPPres ' If PPPres.Slides.Count = 0 Then ' Set PPSlide = getNewSlide(PPPres) ' End If For Each cht In wksChartsFromSheet.ChartObjects Set PPSlide = getNewSlide(PPPres) cht.CopyPicture PPSlide.Select PPSlide.Shapes.Paste.Select PPSlide.Application.ActiveWindow.Selection.ShapeRange.Align msoAlignMiddles, True PPSlide.Application.ActiveWindow.Selection.ShapeRange.Align msoAlignCenters, True PPSlide.Select Next cht Set cht = Nothing Set PPSlide = Nothing Set PPPres = Nothing End Sub Sub TestExecute() Call ExportChartsToPPT(Sheet2) End Sub
Attachment | Size |
---|---|
ChartToPPT.xls | 35 KB |
»
- Vishesh's blog
- Login or register to post comments
- 66935 reads
Question
Hello Vishesh,
I appreciate the code you provided. It works so well. I do have a few questions:
1) Is it possible to make the graphs/charts a little larger when exported into the powerpoint application?
2) Is it possible to modify the code to where the graphs/charts are ADDED to an existing powerpoint file instead of creating a completely new one?
3) Is it possible to modify the code to where you can specifically select which graphs/charts to add to the powerpoint file?
I look forward to your reply!!!
Excel charts - Powerpoint link-up
Hello,
I´m Irina.
I really need some further help reagrds Excel features.
Was not able to find any solution to my question in the sources available in Internet =((
So the problem as follows:
I have a few tables on the separate Excel documents- let´s say 3 charts. All of them are connected between each other by formulas. And when I change the data in the first table, the results are changing and updating in the other charts too automatically.
Now I need to make a powerpoint presentation with the use of those tables. Since I have 3 tables, I have created 3 powerpoint slides and linked the excel tables to those slides. I cpied it in the way to get the preso updated whenever the Excel sheet updates.
But though the info changes simulteniously in all 3 excel tables, in the preso it changes just on the slide containing the very table I deal with in excel.
Not on all 3 slides ((((
Is there any way to link the slides between themselves like excel sheets in order to get the charts updated both in excel and on all powerpoint slides just with one click
whenever I change the original data the the 1st base excel table?
I will so much appreciate any feedback cause I have already the headache because of this. And this neeeed to be done.
Thanks u in advance.
Regards,
Irina
Many thanks
Many thanks for this very useful code. Probably just worth mentioning that the appropriate MS Powerpoint Object Library needs to be activated under Tools -> References. In my case (Excel 2007) it was inactive by default.
Yes, my mistake. I should
Yes, my mistake. I should have mentioned. However, here is the modified code that doesn't require the PowerPoint library to be added.
Function getPPPres() As Object
Dim PPApp As Object
'Reference instance of PowerPoint
On Error Resume Next
'Check whether PowerPoint is running
Set PPApp = GetObject(, "PowerPoint.Application")
If PPApp Is Nothing Then
'PowerPoint is not running, create new instance
Set PPApp = CreateObject("PowerPoint.Application")
'For automation to work, PowerPoint must be visible
PPApp.Visible = True
End If
On Error GoTo 0
'Reference presentation and slide
On Error Resume Next
If PPApp.Windows.Count > 0 Then
'There is at least one presentation
'Use existing presentation
Set getPPPres = PPApp.ActivePresentation
Else
'There are no presentations
'Create New Presentation
Set getPPPres = PPApp.Presentations.Add
End If
Set PPApp = Nothing
End Function
Function getNewSlide(PPPres As Object) As Object
Set getNewSlide = PPPres.Slides.Add(PPPres.Slides.Count + 1, 12)
End Function
Sub ExportChartsToPPT(wksChartsFromSheet As Worksheet)
Dim PPPres As Object
Dim PPSlide As Object
Dim cht As ChartObject
If wksChartsFromSheet.ChartObjects.Count = 0 Then
MsgBox "No Chart to Export to Powerpoint", vbInformation, ""
Exit Sub
End If
Set PPPres = getPPPres
' If PPPres.Slides.Count = 0 Then
' Set PPSlide = getNewSlide(PPPres)
' End If
For Each cht In wksChartsFromSheet.ChartObjects
Set PPSlide = getNewSlide(PPPres)
cht.CopyPicture
PPSlide.Select
PPSlide.Shapes.Paste.Select
PPSlide.Application.ActiveWindow.Selection.ShapeRange.Align msoAlignMiddles, True
PPSlide.Application.ActiveWindow.Selection.ShapeRange.Align msoAlignCenters, True
PPSlide.Select
Next cht
Set cht = Nothing
Set PPSlide = Nothing
Set PPPres = Nothing
End Sub
Thanx
It works like heaven!! thanx :-)
Need Help
Can any One help me to write a excel macros that extract notes from powerpoint please??
Linked Charts
How can I copy charts from Excel to a power point presentation but without ultimately have the charts linked to the Excel file?
I mean, I can export them and have them in the slides, but I want to lose the link with the Excel, I need all the info to be in the slide itself as a part of it.
I have tried the link:=msoFalse etc and nothing seems to work.
Thanks
Regards
Manu
Delink Powerpoint chart from Excel
Check this link to delink the chart
http://erlandsendata.no/?p=3653
Me Too!!
I've spent the day trying to export charts to Excel but without the data link back to Excel. I've read that it can be done, but can't seem to get it to work.
copy the chart, and paste
copy the chart, and paste special as an enhanced metafile