Change MSGraph Axis Range in VBA

A

Alex Osbaldeston

Hi,

The query is basically as per the subject line. How do I use VBA code
to alter the y axis range of an MSGraph Chart. The Chart shape is
called "Chart". All I want to do is make the y axis go from 0 to 1.2.
I don't care about the major units and minor units as the axis is not
actually displayed. Which brings me onto...
As the axis is not actually shown in the chart, I don't know whether
the code would need to first show the axis, then change it, then set
the axis to not be shown (as one would have to do if you were doing it
manually)???
I'd be very grateful if someone could help here as I have 95
presentations each with 6 charts that need changing so I'm going to be
still doing it this time next week if I can't write a macro!

Many thanks
Alex
 
A

Andy Pope

Hi Alex,

Try this code sample, watch for line wrapping.

Sub SetYAxis()
Dim objGraph As Graph.Application
Dim objChart As Graph.Chart

Set objGraph = ActivePresentation.Slides(1).Shapes("Chart
1").OLEFormat.Object.Application
Set objChart = objGraph.Chart
With objChart
.HasAxis(2, 1) = True
With .Axes(2, 1)
.MaximumScale = 1.2
.MinimumScale = 0
End With
.HasAxis(2, 1) = False
End With
objGraph.Update
objGraph.Quit

Set objChart = Nothing
Set objGraph = Nothing
End Sub


Alex said:
Hi,

The query is basically as per the subject line. How do I use VBA code
to alter the y axis range of an MSGraph Chart. The Chart shape is
called "Chart". All I want to do is make the y axis go from 0 to 1.2.
I don't care about the major units and minor units as the axis is not
actually displayed. Which brings me onto...
As the axis is not actually shown in the chart, I don't know whether
the code would need to first show the axis, then change it, then set
the axis to not be shown (as one would have to do if you were doing it
manually)???
I'd be very grateful if someone could help here as I have 95
presentations each with 6 charts that need changing so I'm going to be
still doing it this time next week if I can't write a macro!

Many thanks
Alex

--

Cheers
Andy

http://www.andypope.info
 

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