VBA Code to switch axis on in microsoft graph

D

David Lauberts

Dear all

I have a form that shows 2 graphs, one is a 'background' and has its axis
and titles 'hidden', the second graph overlays it and has both. The first
graph has had its axis scales max and mins set the same as the top graph
before I switched of the axis.

I want to use basic to change the axis maximiums and miniums, I can do this
for the front graph which has the axis already there but can't do it for the
graph where i have switched of the axis. I think the problem is that I have
to switch them on but I can't seem to do it. I am sure it is to do with
'.HasAxis' but can't seem to get it in the right place.

Any body with any ideas?

Code I am using is:
The error I get is that id I do not try to set the axis up is 1004 'Unable
to set the MaximumScale property of the Axis class'
with Xaxis.HasAxis I get 438 'Object doesn't support this property or
method'

Any help would be appreciated- do I have to somehow refer to the chart
object? if so any suggestions?

Function Test()

Dim obj, XAxis, YAxis As Object
Dim intXMax, intXMin, intYMax, intYMin As Integer
intXMax = 21
intXMin = 5
intYMax = 100
intYMin = 0
'Front Graph Settings
Set obj = Forms("MyGraph")("FrontGraph").Object
Set XAxis = obj.Axes(1)
Set YAxis = obj.Axes(2)
'Gridlines
XAxis.HasMinorGridlines = False
XAxis.HasMinorGridlines = False
YAxis.HasMajorGridlines = True
YAxis.HasMajorGridlines = True
'Axis
XAxis.HasTitle = True
YAxis.HasTitle = True
XAxis.AxisTitle.Caption = "Time"
YAxis.AxisTitle.Caption = "Score"
'Scale
XAxis.MaximumScale = intXMax
YAxis.MaximumScale = intYMax
XAxis.MinimumScale = intXMin
YAxis.MinimumScale = intYMin
'Background Graph Settings
Set obj = Forms("MyGraph")("BackgroundGraph").Object
Set XAxis = obj.Axes(1)
Set YAxis = obj.Axes(2)
'Gridlines
XAxis.HasMinorGridlines = False
YAxis.HasMinorGridlines = False
YAxis.HasMajorGridlines = True
YAxis.HasMajorGridlines = True
'Axis
'Not needed
'Scale
XAxis.HasAxis
YAxis.HasAxis
XAxis.MaximumScale = intXMax
YAxis.MaximumScale = intYMax
XAxis.MinimumScale = intXMin
YAxis.MinimumScale = intYMin
End Function
 

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