Paste chart to PowerPoint with option "Keep source formatting & embed workbook" - VBA

Djani

Board Regular
Joined
Aug 26, 2015
Messages
61
Dear all,

I found a working code which has been made a long time ago - thanks to AlphaFrog.
However, this code pastes the charts as a picture. I want the charts to be pasted with the option "Keep source formatting & embed workbook" in the PowerPoint slides.

Code:
Sub ChartToPresentation()
    ' Uses Early Binding to the PowerPoint Object Model
    ' Set a VBE reference to Microsoft PowerPoint Object Library
    Dim PPApp  As PowerPoint.Application
    Dim PPPres As PowerPoint.Presentation
    Dim PPSlide As PowerPoint.Slide
    
        ' Reference existing instance of PowerPoint
        Set PPApp = GetObject(, "Powerpoint.Application")
        ' Reference active presentation
        Set PPPres = PPApp.ActivePresentation
        PPApp.ActiveWindow.ViewType = ppViewSlide
        
'Copy "Chart 1" on "Sheet1" to Slide # 2
        ' Copy "Chart 1" on "Sheet1" as a picture
        ActiveWorkbook.Sheets("Sheet1").ChartObjects("Chart 1").CopyPicture
        ' Paste chart  to Slide # 2
        With PPPres.Slides(2).Shapes.Paste
            ' Align pasted chart
            .Align msoAlignCenters, True
            .Align msoAlignMiddles, True
        End With
        
'Copy "Chart 1" to from "Sheet3" to Slide # 4
        ' Copy "Chart 1" on "Sheet3" as a picture
        ActiveWorkbook.Sheets("Sheet3").ChartObjects("Chart 1").CopyPicture
        ' Paste chart  to Slide # 4
        With PPPres.Slides(4).Shapes.Paste
            ' Align pasted chart
            .Align msoAlignCenters, True
            .Align msoAlignMiddles, True
        End With
        
        ' Clean up
        Set PPSlide = Nothing
        Set PPPres = Nothing
        Set PPApp = Nothing
        
End Sub

I believe I need this piece of code, but I don't know how to integrate it in the current one:

Code:
PPTApp.CommandBars.ExecuteMso "PasteExcelChartSourceFormatting"

Can any of you help me out?
 

Excel Facts

Which came first: VisiCalc or Lotus 1-2-3?
Dan Bricklin and Bob Frankston debuted VisiCalc in 1979 as a Visible Calculator. Lotus 1-2-3 debuted in the early 1980's, from Mitch Kapor.

Forum statistics

Threads
1,223,243
Messages
6,170,971
Members
452,371
Latest member
Frana

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top