Excel 9.0 Library and Generating chart with VBA

[code]
Function generateGraphs(fileName As String, startCol As Long, ByRef xlApp As Excel.Application, _
ByRef xlShtSrc1 As Excel.Worksheet, ByRef xlShtSrc2 As Excel.Worksheet, _
ByRef xlShtSrc3 As Excel.Worksheet, ByRef xlShtDest As Excel.Worksheet)
Dim colsToDraw As Long
Dim rowNumber As Integer

Dim endCol As Long
Dim startColName As String
Dim endColName As String
Dim xlChart As Chart
Dim chartCount As Integer

Dim pName As String

endCol = xlShtSrc1.UsedRange.Columns.count

startColName = strColId(startCol)
endColName = strColId(endCol)
rowNumber = 4

Dim i As Integer
For i = 4 To xlShtSrc1.UsedRange.Rows.count
rowNumber = i
If (Not isEmpty(xlShtSrc1.Cells(rowNumber, 1).Value)) Then
pName = xlShtSrc1.Cells(rowNumber, 3) & "-" & xlShtSrc1.Cells(rowNumber, 2)
If (Not isEmpty(xlShtSrc1.Cells(rowNumber, 4))) Then
pName = pName & "-" & xlShtSrc1.Cells(rowNumber, 4)
End If

xlShtDest.Select
Set xlChart = xlApp.Charts.Add
xlApp.ActiveChart.ChartType = xlLineMarkers
xlApp.ActiveChart.SetSourceData Source:=xlApp.Sheets(xlShtSrc1.name).Range(startColName & rowNumber & ":" & endColName & rowNumber), PlotBy:=xlColumns
xlApp.ActiveChart.Location where:=xlLocationAsObject, name:=xlShtDest.name
chartCount = xlShtDest.ChartObjects.count

With xlApp.ActiveChart
.HasTitle = True
.ChartTitle.Characters.Caption = pName
.ApplyDataLabels (xlDataLabelsShowValue)
.Legend.Position = xlLegendPositionTop
MsgBox ("=SERIES(""" & xlShtSrc1.name & """,'" & xlShtSrc1.name & "'!" & startColName & "1:" & endColName & "1,'" & xlShtSrc1.name & "'!" & startColName & rowNumber & ":" & endColName & rowNumber & ",1)" & _
vbCrLf & "=SERIES(""" & xlShtSrc2.name & """,'" & xlShtSrc2.name & "'!" & startColName & "1:" & endColName & "1,'" & xlShtSrc2.name & "'!" & startColName & rowNumber & ":" & endColName & rowNumber & ",1)")
.SeriesCollection(1).Formula = "=SERIES(""" & xlShtSrc1.name & """,'" & xlShtSrc1.name & "'!" & startColName & "1:" & endColName & "1,'" & xlShtSrc1.name & "'!" & startColName & rowNumber & ":" & endColName & rowNumber & ",1)"
.SeriesCollection(2).Formula = "=SERIES(""" & xlShtSrc2.name & """,'" & xlShtSrc2.name & "'!" & startColName & "1:" & endColName & "1,'" & xlShtSrc2.name & "'!" & startColName & rowNumber & ":" & endColName & rowNumber & ",1)"
.SeriesCollection(3).Formula = "=SERIES(""" & xlShtSrc3.name & """,'" & xlShtSrc3.name & "'!" & startColName & "1:" & endColName & "1,'" & xlShtSrc3.name & "'!" & startColName & rowNumber & ":" & endColName & rowNumber & ",1)"
.Parent.Width = 300
.Parent.Height = 200
.Parent.Left = 0 + ((chartCount - 1) Mod 2) * (xlApp.ActiveChart.Parent.Width + 10)
.Parent.Top = 0 + Int((chartCount - 1) / 2) * (xlApp.ActiveChart.Parent.Height + 10)
End With
End If
Next
End Function
[/code]

The error i have is "Unable toset formula property of series class".

The reason i think its Excel 9.0 is, its working fine on other computer with Excel 10.0. AND i cannot update it and it HAS to work with 9.0

Please help



Answer this question

Excel 9.0 Library and Generating chart with VBA

  • Excel 9.0 Library and Generating chart with VBA