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.
ISIGestAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

irudykCommented:
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
            ActiveDocument.InlineShapes(i).Activate
            Set msGraph = ActiveDocument.InlineShapes(i).OLEFormat.Object
            msGraph.Application.Datasheet.Range("A1").Value = 50
            msGraph.Application.Quit
            Set msGraph = Nothing
            Exit For
        End If
    End If
Next i

End Sub

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
System Programming

From novice to tech pro — start learning today.