How to export single or all charts from Excel worksheets to PowerPoint?
Sometimes, you may need to export a chart or all charts from Excel to PowerPoint for some purpose. This article is talking about how to achieve it.
Export single chart or all charts from Excel worksheet to PowerPoint with VBA code
Export single chart or all charts from Excel worksheet to PowerPoint with VBA code
This section will introduce VBA codes to export a single chart or all charts from workbook to PowerPoint. Please do as follows.
1. Press the Alt + F11 keys together to open the Microsoft Visual Basic for Applications window.
2. In the Microsoft Visual Basic for Applications window, click Tools > References as below screenshot shown.
3. In the References – VBAProject dialog box, scroll down to find and check the Microsoft PowerPoint Object Library option, and then click the OK button. See screenshot:
4. Then click Insert > Module.
5. If you want to export a single chart to PowerPoint, please go to select the chart in worksheet, then return to the Microsoft Visual Basic for Applications window, copy and paste the below VBA code into the Module window.
VBA code: Export single chart from Excel worksheet to PowerPoint
Sub SingleActiveChartToPowerPoint_EarlyBinding1()
'Updated by Extendoffice 2017/9/15
Dim pptApp As PowerPoint.Application
Dim pptPres As PowerPoint.Presentation
Dim pptSlide As PowerPoint.Slide
Dim pptShape As PowerPoint.Shape
Dim pptShpRng As PowerPoint.ShapeRange
Dim xActiveSlideNow As Long
On Error Resume Next
If ActiveChart Is Nothing Then
MsgBox "Select a chart and try again!", vbExclamation, "KuTools For Excel"
Exit Sub
End If
Set pptApp = GetObject(, "PowerPoint.Application")
If pptApp Is Nothing Then
Set pptApp = CreateObject("PowerPoint.Application")
Set pptPres = pptApp.Presentations.Add
Set pptSlide = pptPres.Slides.Add(1, ppLayoutBlank)
Else
If pptApp.Presentations.Count > 0 Then
Set pptPres = pptApp.ActivePresentation
If pptPres.Slides.Count > 0 Then
xActiveSlideNow = pptApp.ActiveWindow.View.Slide.SlideIndex
Set pptSlide = pptPres.Slides(xActiveSlideNow)
Else
Set pptSlide = pptPres.Slides.Add(1, ppLayoutBlank)
End If
Else
Set pptPres = pptApp.Presentations.Add
Set pptSlide = pptPres.Slides.Add(1, ppLayoutBlank)
End If
End If
ActiveChart.ChartArea.Copy
With pptSlide
.Shapes.Paste
Set pptShape = .Shapes(.Shapes.Count)
Set pptShpRng = .Shapes.Range(pptShape.Name)
End With
With pptShpRng
.Align msoAlignCenters, True
.Align msoAlignMiddles, True
End With
pptShpRng.Select
End Sub
If you want to export all charts from workbook, please copy and paste the below VBA code into the Module window.
VBA code: Export all charts from Excel worksheets to PowerPoint
Option Explicit
'Updated by Extendoffice 2017/9/15
Dim pptApp As PowerPoint.Application
Dim pptPres As PowerPoint.Presentation
Dim pptSlide As PowerPoint.Slide
Dim pptSlideCount As Integer
Sub ChartsToPowerPoint()
Dim xSheet As Worksheet
Dim xChartsCount As Integer
Dim xChart As Object
Dim xActiveSlideNow As Integer
On Error Resume Next
For Each xSheet In ActiveWorkbook.Worksheets
xChartsCount = xChartsCount + xSheet.ChartObjects.Count
Next xSheet
If xChartsCount = 0 Then
MsgBox "Sorry, there are no charts to export!", vbCritical, "Ops"
Exit Sub
End If
Set pptApp = GetObject(, "PowerPoint.Application")
If pptApp Is Nothing Then
Set pptApp = CreateObject("PowerPoint.Application")
Set pptPres = pptApp.Presentations.Add
Set pptSlide = pptPres.Slides.Add(1, ppLayoutBlank)
Else
If pptApp.Presentations.Count > 0 Then
Set pptPres = pptApp.ActivePresentation
If pptPres.Slides.Count > 0 Then
xActiveSlideNow = pptApp.ActiveWindow.View.Slide.SlideIndex
Set pptSlide = pptPres.Slides(xActiveSlideNow)
Else
Set pptSlide = pptPres.Slides.Add(1, ppLayoutBlank)
End If
Else
Set pptPres = pptApp.Presentations.Add
Set pptSlide = pptPres.Slides.Add(1, ppLayoutBlank)
End If
End If
For Each xSheet In ActiveWorkbook.Worksheets
For Each xChart In xSheet.ChartObjects
Call pptFormat(xChart.Chart)
Next xChart
Next xSheet
For Each xChart In ActiveWorkbook.Charts
Call pptFormat(xChart)
Next xChart
Set pptSlide = Nothing
Set pptPres = Nothing
Set pptApp = Nothing
MsgBox "The charts were copied successfully to the new presentation!", vbInformation, "KuTools For Excel"
End Sub
Private Sub pptFormat(xChart As Chart)
Dim xCharTiTle As String
Dim I As Integer
On Error Resume Next
xCharTiTle = xChart.ChartTitle.Text
xChart.ChartArea.Copy
pptSlideCount = pptPres.Slides.Count
Set pptSlide = pptPres.Slides.Add(pptSlideCount + 1, ppLayoutBlank)
pptSlide.Select
pptSlide.Shapes.PasteSpecial ppPasteJPG
If xCharTiTle <> "" Then
pptSlide.Shapes.AddTextbox msoTextOrientationHorizontal, 12.5, 20, 694.75, 55.25
End If
For I = 1 To pptSlide.Shapes.Count
With pptSlide.Shapes(I)
Select Case .Type
Case msoPicture:
.Top = 87.84976
.left = 33.98417
.Height = 422.7964
.Width = 646.5262
Case msoTextBox:
With .TextFrame.TextRange
.ParagraphFormat.Alignment = ppAlignCenter
.Text = xCharTiTle
.Font.Name = "Tahoma (Headings)"
.Font.Size = 28
.Font.Bold = msoTrue
End With
End Select
End With
Next I
End Sub
6. Press the F5 key or click the Run button to run the code. Then a new PowerPoint will be opened with the selected chart or all charts imported. And you will get a Kutools for Excel dialog box as below screenshot shown, please click the OK button.
Related articles:
- How to save, export multiple/all sheets to separate csv or text files in Excel?
- How to save selection or entire workbook as PDF in Excel?
Best Office Productivity Tools
Supercharge Your Excel Skills with Kutools for Excel, and Experience Efficiency Like Never Before. Kutools for Excel Offers Over 300 Advanced Features to Boost Productivity and Save Time. Click Here to Get The Feature You Need The Most...
Office Tab Brings Tabbed interface to Office, and Make Your Work Much Easier
- Enable tabbed editing and reading in Word, Excel, PowerPoint, Publisher, Access, Visio and Project.
- Open and create multiple documents in new tabs of the same window, rather than in new windows.
- Increases your productivity by 50%, and reduces hundreds of mouse clicks for you every day!