VBA for MS-Graph

M

mcalex

Hi there. Can someone (who's done it before) give me an idea of how
to manipulate a graph through vba. I try to do Record Macro from
powerpoint, but it seems to only create code like:
ActiveWindow.Selection.ShapeRange.OLEFormat.DoVerb Index:=2.

If I wanted to change the type of graph from (say) bar chart to 3d bar
chart, or change the color of the data series, what would the code
look like?

I've managed to create the chart using

dim shpGraph as Powerpoint.Shape
Set shpGraph = .Shapes.AddOLEObject(ClassName:="MSGraph.Chart",
Link:=msoFalse)

but I can't see any way of manipulating my shpGraph to make it a 3d
bar chart shape with red and yelow data series. Hope I'm making
sense, I'm a bit new to the MS way of doing things.

Thx in advance
mcalex
 
H

haroldk

In order to change the Chart type you will need to use the Graph library.
This sample will change the type to a pie chart

Sub sGraph()
'set reference to Microsoft Graph
Dim myChart As Graph.Chart
Set myChart = ActivePresentation.Slides(1).Shapes(1).OLEFormat.Object
'activate the chart
myChart.Activate
myChart.ChartType = xlPie
'this saves the changes
myChart.Application.Update
'use this to deactivate the chart
ActivePresentation.Slides(1).Shapes(2).Select

End Sub
 
M

mcalex

Thx haroldk

One other thing ... when I create the graph, it gets put in the top
left corner of the slide. I don't seem to be able to align the graph
using shapeRng.align msoMiddles, true. Is there a better way?

Much appreciated.
Alex
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top