0
votes
 PowerPoint.Shape shapeObject = slide.Shapes(0);
 Excel.ListObject listObject = reader.GetListObject(tableName);

  //code to insert the able into the powerpoint shape.

So I would like to put the ListObject, ChartObject from Excel into a Shape in powerpoint, is this possible?

this chart and many other chart will be going into the powerpoint So I know how to pick a Excel.ChartObject from excel sheet or table, but how do I put it as a chart with same content into a slide.

1
@mjwills I have tried number of solutions but I cant get one to work, Like Copy Paste Solution, Text Work fine but I really want to do it for Charts and Tables that are ranges in Excel - Anwar Al-fathli

1 Answers

0
votes

Since you post with a VBA tag, here's VBA code that inserts a Chart into PowerPoint. Note that in order to use Excel.Chart or workbook you need a reference to the Excel object model (PIAs) in your solution. Otherwise use the generic object, but then you won't have any Intellisense.

The AddOleObject method is the key for importing something from an OLE Server. Through OLEFormat you get basic information about the object; OLEFormat.Object gives you access to the object, itself. Note that as far as PowerPoint is concerned, this is a Shape object.

Edit: The lines commented out in the code below create a new object and show how to access the underlying Excel objects.

In order to bring in and link to an existing workbook you need to specify the file name (but not the OLE class!) and that it should be linked. Only the "top-most" Sheet in the Workbook will be displayed. Note that the linked object cannot be manipulated like the independent object - the actual file must be opened in Excel. The user can do this by double-clicking the object; code can do it using shp.OLEFormat.DoVerb 1.

Sub InsertExcelChart()
    Dim p As Presentation
    Dim s As Slide
    Dim shp As Shape
    Dim wb As Excel.Workbook 'Object
    Dim chart As Excel.chart 'object

    Set p = ActivePresentation
    Set s = p.Slides(1)
    Set shp = s.Shapes.AddOLEObject( _
        FileName:="C:\Users\Cindy Meister\Documents\SampleChart.xlsx", _
        Link:=msoTrue, DisplayAsIcon:=msoFalse)

    'Set shp = s.Shapes.AddOLEObject(10, 10, 600, 200, "Excel.Chart")
    'Debug.Print shp.OLEFormat.ProgID, shp.OLEFormat.Object.Name

    'Set wb = shp.OLEFormat.Object
    'Set chart = wb.Charts(1)
    'Debug.Print wb.Name
    'Debug.Print chart.ChartType
End Sub