Updating MSGraph datasheet in Word from VB

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • blurbology
    New Member
    • Nov 2007
    • 2

    Updating MSGraph datasheet in Word from VB

    I have a word document that contains a Graph (MSGraph). I am trying to update the Chart's datasheet with new values, but I cannot seem to get the correct reference for the chart object. What I am trying is:

    ---------------------------------------

    Dim oShape As Microsoft.Offic e.Interop.Word. Shape
    Dim oGraphChart As Microsoft.Offic e.Interop.Graph .Chart

    word = CreateObject("W ord.Application ")
    word.visible = True
    doc = word.Documents. Open(My.Setting s.FormsPath & "\49.doc")

    oShape = doc.Shapes(1).O LEFormat.Object
    oGraphChart = oShape.OLEForma t.Object

    --------------------------------------------

    I am gettig a NullReferenceEx ception(Object reference not set to an instance of an object) at:

    oShape = doc.Shapes(1).O LEFormat.Object

    however, if I do not have an exisiting chart, and simply add a new one using:

    oShape = doc.Shapes.AddO LEObject(Left:= 40, Top:=400, Width:=400, Height:=400, ClassType:="MSG raph.Chart", DisplayAsIcon:= False)

    then this provides a reference to the chart object that I can use.

    Any suggestions?
Working...