Aha! After falling down on this one, I figured it out.
When Excel creates the chart, it knows what's on its own mind. So it
automatically puts Series 2 onto the second set of axes. When you rerun the
macro, however, Excel has no idea what YOU wanted, so it puts both series
onto the first axes. Axes(xlYada, xlSecondary).HasTitle is meaningless,
because you have no Axes(xlYada, xlSecondary) yet. You need to insert this
before the .HasAxis statement:
.SeriesCollection(2).AxisGroup = 2
Then Excel gets the hint, and knows you really really want two Y axes,
despite selecting TypeName:="Lines on 2 Axes".
Since you need the line to assign series 2 to the secondary axes, you might
as well just use
.ChartType = xlLineMarkers
instead of
.ChartType:=xlBuiltIn, TypeName:="Lines on 2 Axes"
I was going to suggest this even before trying to record and run the same
macro you had trouble with.
- Jon
_______
In article <FIXB7.6006$nj.9...@typhoon.austin.rr.com>, Steve Stowers said...
>
>This is a multi-part message in MIME format.
>
>------=_NextPart_000_0038_01C15D4E.1F4B8600
>Content-Type: text/plain;
> charset="iso-8859-1"
>Content-Transfer-Encoding: quoted-printable
>
>Hello,
>
>I am trying to create an addin to create a chart of type "lines on 2 =
>axes"
>as shown below. The problem however is that I continually get an error
>message "Method 'Axes' of object '_Chart' failed, run-time error 1004.
>This occurs when trying to set the titles for the secondary axes. I
>assume this should work since the macro created it but unfortunately it
>does not. Highlighted below is where the error occurs:
>
> .Axes(xlCategory, xlSecondary).HasTitle =3D True
> .Axes(xlCategory, xlSecondary).AxisTitle.Characters.Text =3D
>"Special Cause Flag"
>
>
>Any comments would be greatly appreciated.
>
>THanks,
>
>Steve Stowers
>
>
>sample code:
>
> public co as chartobject
> Set co =3D Worksheets("sheet1").ChartObjects.Add(0, 0, 500, 300)
>
> co.Chart.ApplyCustomType ChartType:=3DxlBuiltIn, TypeName:=3D _
> "Lines on 2 Axes"
>
> co.Chart.SetSourceData Source:=3DSheets("Sheet1").Range("A1"),
>PlotBy:=3D _
> xlColumns
>
> co.Chart.SeriesCollection.NewSeries
> co.Chart.SeriesCollection(1).XValues =3D "=3D'test =
>plot.xls'!X_ValueC"
> co.Chart.SeriesCollection(1).Values =3D "=3D'test plot.xls'!IUCLC"
> co.Chart.SeriesCollection(1).Name =3D "=3D""Upper Process Limit"""
>
> co.Chart.SeriesCollection.NewSeries
> co.Chart.SeriesCollection(2).XValues =3D "=3D'test =
>plot.xls'!X_ValueC"
> co.Chart.SeriesCollection(2).Values =3D "=3D'test plot.xls'!ILCLC"
> co.Chart.SeriesCollection(2).Name =3D "=3D""Lower Process Limit"""
>
> co.Chart.Location Where:=3DxlLocationAsObject, Name:=3D"Sheet1"
>
> With ActiveChart
> .HasTitle =3D False
> .Axes(xlCategory, xlPrimary).HasTitle =3D True
> .Axes(xlCategory, xlPrimary).AxisTitle.Characters.Text =3D
>"Period"
> .Axes(xlValue, xlPrimary).HasTitle =3D True
> .Axes(xlValue, xlPrimary).AxisTitle.Characters.Text =3D
>"Individual Value"
> .ChartArea.Interior.ColorIndex =3D xlNone
> End With
>
>******** problem section
> With ActiveChart
> .HasTitle =3D False
> .Axes(xlCategory, xlSecondary).HasTitle =3D True
> .Axes(xlCategory, xlSecondary).AxisTitle.Characters.Text =3D
>"Special Cause Flag"
> .Axes(xlValue, xlSecondary).HasTitle =3D True
> .Axes(xlValue, xlSecondary).AxisTitle.Characters.Text =3D =
>"Initial
>Value"
> End With
>
>
>------=_NextPart_000_0038_01C15D4E.1F4B8600
>Content-Type: text/html;
> charset="iso-8859-1"
>Content-Transfer-Encoding: quoted-printable
>
><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
><HTML><HEAD>
><META http-equiv=3DContent-Type content=3D"text/html; =
>charset=3Diso-8859-1">
><META content=3D"MSHTML 5.50.4522.1800" name=3DGENERATOR>
><STYLE></STYLE>
></HEAD>
><BODY bgColor=3D#ffffff>
><DIV><FONT face=3DArial size=3D2>
><DIV><FONT face=3DArial size=3D2>Hello,</FONT></DIV>
><DIV><FONT face=3DArial size=3D2></FONT> </DIV>
><DIV>I am trying to create an addin to create a chart of type =
>"lines on 2=20
>axes"<BR>as shown below. The problem however is that I continually =
>get an=20
>error<BR>message "Method 'Axes' of object '_Chart' failed, run-time =
>error=20
>1004.<BR>This occurs when trying to set the titles for the secondary =
>axes. =20
>I<BR>assume this should work since the macro created it but =
>unfortunately=20
>it<BR>does not. Highlighted below is where the error =
>occurs:<BR></DIV>
><DIV><FONT face=3DArial size=3D2><FONT face=3D"Times New Roman"=20
>size=3D3> <FONT color=3D#ff0000>.Axes(xlCategory, =
>xlSecondary).HasTitle =3D=20
>True<BR> .Axes(xlCategory, xlSecondary).AxisTitle.Characters.Text=20
>=3D<BR>"Special Cause Flag"</FONT></FONT><BR></FONT></DIV><FONT =
>face=3DArial=20
>size=3D2></FONT>
><DIV><BR>Any comments would be greatly =
>appreciated.<BR><BR>THanks,<BR><BR>Steve=20
>Stowers<BR><BR></DIV>
><DIV><FONT color=3D#0000ff><FONT face=3DArial size=3D2>sample=20
>code:</FONT><BR><BR> public co as=20
>chartobject<BR> Set co =3D=20
>Worksheets("sheet1").ChartObjects.Add(0, 0, 500, =
>300)<BR><BR> =20
>co.Chart.ApplyCustomType ChartType:=3DxlBuiltIn, TypeName:=3D=20
>_<BR> "Lines on 2 =
>Axes"<BR><BR> =20
>co.Chart.SetSourceData =
>Source:=3DSheets("Sheet1").Range("A1"),<BR>PlotBy:=3D=20
>_<BR> =20
>xlColumns<BR><BR> =20
>co.Chart.SeriesCollection.NewSeries<BR> =20
>co.Chart.SeriesCollection(1).XValues =3D "=3D'test=20
>plot.xls'!X_ValueC"<BR> =
>co.Chart.SeriesCollection(1).Values =3D=20
>"=3D'test plot.xls'!IUCLC"<BR> =
>co.Chart.SeriesCollection(1).Name=20
>=3D "=3D""Upper Process Limit"""<BR><BR> =20
>co.Chart.SeriesCollection.NewSeries<BR> =20
>co.Chart.SeriesCollection(2).XValues =3D "=3D'test=20
>plot.xls'!X_ValueC"<BR> =
>co.Chart.SeriesCollection(2).Values =3D=20
>"=3D'test plot.xls'!ILCLC"<BR> =
>co.Chart.SeriesCollection(2).Name=20
>=3D "=3D""Lower Process Limit"""<BR><BR> =
>co.Chart.Location=20
>Where:=3DxlLocationAsObject, Name:=3D"Sheet1"<BR><BR> =
>With=20
>ActiveChart<BR> .HasTitle =3D=20
>False<BR> .Axes(xlCategory,=20
>xlPrimary).HasTitle =3D =
>True<BR> =20
>.Axes(xlCategory, xlPrimary).AxisTitle.Characters.Text=20
>=3D<BR>"Period"<BR> =
>.Axes(xlValue,=20
>xlPrimary).HasTitle =3D =
>True<BR> =20
>.Axes(xlValue, xlPrimary).AxisTitle.Characters.Text =3D<BR>"Individual=20
>Value"<BR> =20
>.ChartArea.Interior.ColorIndex =3D xlNone<BR> End=20
>With<BR><BR></FONT><FONT color=3D#ff0000>******** problem=20
>section<BR> With=20
>ActiveChart<BR> .HasTitle =3D=20
>False<BR> .Axes(xlCategory,=20
>xlSecondary).HasTitle =3D =
>True<BR> =20
>.Axes(xlCategory, xlSecondary).AxisTitle.Characters.Text =3D<BR>"Special =
>Cause=20
>Flag"<BR> .Axes(xlValue,=20
>xlSecondary).HasTitle =3D =
>True<BR> =20
>.Axes(xlValue, xlSecondary).AxisTitle.Characters.Text =3D=20
>"Initial<BR>Value"<BR> End=20
>With<BR></FONT></DIV></FONT></DIV></BODY></HTML>
>
>------=_NextPart_000_0038_01C15D4E.1F4B8600--
>