PDA

View Full Version : VBA paste/insert msoChart into Powerpoint 2010



LifeLongLean
04-30-2015, 02:18 AM
I am trying to paste/insert an msoChart object with embedded data from the clipboard into PowerPoint 2010 using VBA. (chart created in Excel 2010 and copied to the clipboard).

The only examples that I can find involve either linking the Chart to an Excel file or creating a msoEmbeddedOLEObject.

If I manually paste into PowerPoint 2010 I get a paste option to "Embed Workbook". However it is not available within manual "Paste Special".

So it would seem that something in addition to pasting the chart is needed. But I am unsure what that is or how to go about it.
What I have tried is


Sub PasteExample()
Dim Sld As Slide
Dim Shp As ShapeRange

Set Sld = ActiveWindow.View.Slide

'# This pastes clipboard content as a linked chart
Set Shp = Sld.Shapes.Paste
End Sub

Sub PasteExample2()
Dim Sld As Slide
Dim Shp As ShapeRange

Set Sld = ActiveWindow.View.Slide

'# This option does not work, object is still linked
'Set Shp = Sld.Shapes.PasteSpecial(DataType:=ppPasteDefault, Link:=msoFalse)

'# This option does not work, object is still linked
'Set Shp = Sld.Shapes.PasteSpecial(DataType:=ppPasteShape, Link:=msoFalse)

'# I'm not after OLEObjects
'Set Shp = Sld.Shapes.PasteSpecial(DataType:=ppPasteOLEObject, Link:=msoFalse)
End Sub


Many thanks if you can shed some light.

John Wilson
04-30-2015, 07:28 AM
See if this might work:


Sub PasteExample2()
Dim Sld As Slide
Dim Shp As Shape
Set Sld = ActiveWindow.View.Slide
Sld.Select
Application.CommandBars.ExecuteMso ("PasteExcelChartDestinationTheme")
Set Shp = Sld.Shapes(Sld.Shapes.Count)
End Sub

LifeLongLean
04-30-2015, 07:51 AM
Many thanks

It was just what I was after.

And a lot simpler than I was expecting