Alok Nagar
Alok Nagar

Reputation: 49

Pasting Excel Chart

I would like to paste my Excel chart to a PowerPoint slide using different options available in 'Paste Special' command of VBA.

I am not getting any option through which I could 'paste chart with Embed data in a sheet'

I used the ppPasteOLEObject but that embeds the entire Excel workbook due to which the size of the PowerPoint file increases.

Sub excltoppt()

Dim ppalApp As PowerPoint.Application
Dim ppalPres As PowerPoint.Presentation
Dim ppalSlide As PowerPoint.Slide

Set ppalApp = New PowerPoint.Application

ppalApp.Visible = True
ppalApp.Activate

Set ppalPres = ppalApp.Presentations.Open("C:\Desktop\Template.pptx")

Set ppalSlide = ppalPres.Slides(6)

'here it select data from specific excel sheet #6    
Sheets("S06").Select
Worksheets(1).ChartObjects(1).Copy

'here it paste at the selected specific slide #6
ppalSlide.Shapes.PasteSpecial DataType:=ppPasteText
'ole object option that I have tried is:-
'ppSlide.Shapes.PasteSpecial ppPasteOLEObject

End Sub

I tried to use this option but it is also not working:

PowerPointApp.CommandBars.ExecuteMso ("PasteExcelChartDestinationTheme")

I am using Excel 2016.

Upvotes: 0

Views: 204

Answers (2)

Ahmed Hassan
Ahmed Hassan

Reputation: 110

try this

Sheets("S06").Select
Worksheets("S06").ChartObjects(1).Select
ActiveChart.ChartArea.Copy
ppaslide.select
ppalApp.ActiveWindow.View.Paste

For x = 1 To ppalSlide.Shapes.Count
    If ppalSlide.Shapes(x).HasChart Then
        ppalSlide.Shapes(x).LinkFormat.BreakLink
    End If
Next

Upvotes: 0

Xabier
Xabier

Reputation: 7735

The following worked for me, this pastes the chart into your slide, just not sure how to go about making it have embedded data:

Sub excltoppt()

Dim ppalApp As PowerPoint.Application
Dim ppalPres As PowerPoint.Presentation
Dim ppalSlide As PowerPoint.Slide

    Set ppalApp = New PowerPoint.Application

    ppalApp.Visible = True

    Set ppalPres = ppalApp.Presentations.Open("C:\Desktop\Template.pptx")

    Set ppalSlide = ppalPres.Slides(6)

    Sheets("Sheet1").ChartObjects(1).Copy

    ppalSlide.Shapes.Paste

End Sub

Upvotes: 0

Related Questions