Unable to get the axes property of the chart class

Hi

I have this piece of code to generate a chart. However when I try to set the secondary axes then it throws the error → “unable to get the axes property of the chart class”.

I have tried a lot but cannot make this code work. When I try to create the same chart with Macro recording I get the similar code.

Can anyone help me out with this …

here is the code

Dim xlapp As Variant

Dim xlWbook As Variant

Dim xlsheet As Variant

Dim xlchart As Variant

Set xlApp = CreateObject("Excel.Application")

xlApp.Visible = False



Set xlWbook = xlApp.Workbooks.Add()

Set xlsheet=xlwbook.Worksheets.Add()

Call xlapp.Charts.Add()

Call xlapp.ActiveWorkbook.ActiveChart.ApplyCustomType(21,"Lines on 2 Axes") 

Call xlapp.ActiveWorkbook.ActiveChart.SetSourceData (xlSheet.Range("B5:F9"), 2)

'xlapp.ActiveWorkbook.ActiveChart.SeriesCollection(1).Name ( "asdfdsf")

Call  xlapp.Activeworkbook.ActiveChart.Location (2,"Sheet1")

With xlapp.ActiveWorkbook.ActiveChart

	.HasTitle = True

	.ChartTitle.Characters.Text = "Total LEad Time"

	

	.Axes(1,1).HasTitle = True  

	.Axes(1,1).AxisTitle.Characters.Text = "Month"

	.Axes(2, 1).HasTitle = True

	.Axes(2,1).AxisTitle.Characters.Text = "Percentage Lead Time"

	.Axes(1,2).HasTitle = True <- This is the line with error

	.Axes(1,2).AxisTitle.Characters.Text = "Number of requests closed"

	.Axes(2,2).HasTitle = False

End With

regards

Rohit Kothari

Subject: unable to get the axes property of the chart class

Could it be that you are loading some default macro’s when you start Excel manually?