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.Office.Interop.Word.Shape
Dim oGraphChart As Microsoft.Office.Interop.Graph.Chart
word = CreateObject("Word.Application")
word.visible = True
doc = word.Documents.Open(My.Settings.FormsPath & "\49.doc")
oShape = doc.Shapes(1).OLEFormat.Object
oGraphChart = oShape.OLEFormat.Object
--------------------------------------------
I am gettig a NullReferenceException(Object reference not set to an instance of an object) at:
oShape = doc.Shapes(1).OLEFormat.Object
however, if I do not have an exisiting chart, and simply add a new one using:
oShape = doc.Shapes.AddOLEObject(Left:=40, Top:=400, Width:=400, Height:=400, ClassType:="MSGraph.Chart", DisplayAsIcon:=False)
then this provides a reference to the chart object that I can use.
Any suggestions?