error 13 in Set myChart = Pres.Slides(sn).Shapes.AddChart RRS feed

  • Question

  • Hi All,

    I run a code in order to create a chart from a Macro in powerpoint.

    I succeed to create the chart but I can't store it in a variable Chart. I would like to use this variable later. The two lines concerned:

    Dim myChart As Chart


    Set myChart = Pres.Slides(sn).Shapes.AddChart

    The code is below:

    Public Sub creationPPT()
    Dim objPPT As Object
        Dim cellule As Range
        Dim ppt As PowerPoint.Application
      Dim Slide1 As PowerPoint.Slide
      Dim objPrs As Object
      Dim myChart As Chart
      Dim gChartData As ChartData
    Dim gWorkBook As Excel.Workbook
    Dim gWorkSheet As Excel.Worksheet
      Dim oRange As ChartObjects 'ChartObjects.Chart
      Dim i As Integer
      Dim sn As Integer, shct As Integer
        Dim objDataSheet As Object
        Dim rngData As Range
        Dim intRow As Integer
        Dim intCol As Integer
      Dim Pres As PowerPoint.Presentation
      Set ppt = CreateObject("PowerPoint.Application")
      ppt.Visible = True 
      Set Pres = ppt.Presentations.Open(Filename:="C:\MaPresentation.pptx")
       sn = Pres.Slides.Count + 1
        Pres.Slides.Add sn, ppLayoutBlank
        Set Slide1 = Pres.Slides(sn)
        Set myChart = Pres.Slides(sn).Shapes.AddChart
        'shct = Pres.Slides(sn).Shapes.Count
        'MsgBox shct
        'Set myChart = Pres.Slides(sn).Shapes(shct).Chart
    End Sub


    I have the error: Incompatibily (error 13). I think it is due to "Dim myChart as Chart". I tried to use shapes, shape.. And I Always have the same issue.


    Someone can help me?


    Thank you in advance,




    The most important in the answer is the question

    Friday, June 14, 2013 9:52 AM


All replies

  • Which version of Office are you using?

    Cindy Meister, VSTO/Word MVP, my blog

    Saturday, June 15, 2013 11:14 AM
  • In PowerPoint charts are Shapes so you need to declare...

    Dim shp as PowerPoint.Shape

    Then assuming the slide with your chart is the active slide and it is referenced by "sld" then you can look at each shape on the slide with something like this...

    For Each shp In sld.Shapes
          If shp.Type = Office.MsoShapeType.msoChart Then

    or when you created the chart if you gave it a name you could use

          If shp.Name = "Your chart name"

    If the chart you created was placed inside a PowerPoint placeholder then you will need to look for it inside the placeholder. To PowerPoint the placeholder is also a shape.

    ElseIf shp.Type = Office.MsoShapeType.msoPlaceholder Then
                        If shp.PlaceholderFormat.ContainedType = Microsoft.Office.Core.MsoShapeType.msoChart Then
                            If shp.HasChart Then

    I hope something here is of use to you.

    Kind Regards, Rich ...

    Saturday, June 15, 2013 8:33 PM
  • Hi All,

    thank you for your reply. Please, find below the answer:


    The most important in the answer is the question

    Thursday, June 20, 2013 11:15 AM