Discussion:
How do I edit an existing graph datasheet in word using VBA?
(too old to reply)
JAG777
2006-03-22 16:20:28 UTC
Permalink
I have a .dot file with a number of microsoft graph chart (originally created
from Word tables) objects.
I want to be able to update the datasheet (and tables) of each of the graphs
from the user input captured in text boxes of a user form.
I am struggling with being able to identify the individual chart and then
update its individual data sheet - is this possible?
Jean-Guy Marcil
2006-03-24 17:02:42 UTC
Permalink
Post by JAG777
I have a .dot file with a number of microsoft graph chart (originally
created from Word tables) objects.
I want to be able to update the datasheet (and tables) of each of the
graphs from the user input captured in text boxes of a user form.
I am struggling with being able to identify the individual chart and
then update its individual data sheet - is this possible?
You need to set a reference to "Microsoft Graph 11.0 Object Library" in
Tools > References (VBA Editor menu bar).

Declare some variables like:

Dim o_OLE As Word.OLEFormat
Dim diag As Graph.Chart

Then, set the variables, like:

Set o_OLE = ActiveDocument.Shapes(1).OLEFormat
o_OLE.DoVerb wdOLEVerbShow
Set diag = o_OLE.Object

If it is an inlineshape use
Set o_OLE = ActiveDocument.Shapes(1).OLEFormat

Finally manipulate the object like this:

With diag.Application.DataSheet
.cells
.columns
.rows
End With

or

With diag
.HasLegend = False
.Application.PlotBy = xlColumns
.Width = CentimetersToPoints(25)
.PlotArea.Width = CentimetersToPoints(20)
.Axes(xlCategory, xlPrimary).TickLabelSpacing = 1
.Axes(xlCategory, xlPrimary).TickLabels.Orientation = 90
End With

And do not forget to destroy the objects:

'Deactivate the graph object
diag.Application.Quit

'Clear objects
Set diag = Nothing
Set o_OLE = Nothing
--
Salut!
_______________________________________
Jean-Guy Marcil - Word MVP
***@CAPSsympatico.caTHISTOO
Word MVP site: http://www.word.mvps.org
Loading...