Word.Application OLE Automation Edit Chart data in Word precreated Model

Hi, how I can edit the data of a Word Document with a Chart into programmatically.
Who is Participating?
Okay, it sound like you have embedded chart object within a Word document and you want to edit the data that is used by this chart object.  You didn't mention what version of Word you are using or if the chart object is a Microsoft Excel Chart or a Microsoft Graph Chart object.  Also it this the only chart in the Word document?
So, assuming that you are using Word 2000 or Word 2003 and have only 1 embedded Microsoft Graph Chart object in the document then the following code is an example of how you can edit the value in cell A1 of the datasheet used by the chart.

Sub SetChartData

Dim msGraph As Object
Dim i As Integer

For i = 1 To ActiveDocument.InlineShapes.Count
    If ActiveDocument.InlineShapes(i).Type = wdInlineShapeEmbeddedOLEObject Then
        If InStr(1, ActiveDocument.InlineShapes(i).OLEFormat.ProgID, "MSGraph.Chart", vbTextCompare) <> 0 Then
            Set msGraph = ActiveDocument.InlineShapes(i).OLEFormat.Object
            msGraph.Application.Datasheet.Range("A1").Value = 50
            Set msGraph = Nothing
            Exit For
        End If
    End If
Next i

End Sub

Open in new window

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.