Cyberdude
05-23-2006, 08:59 PM
I have a macro that will search for a chart's line Series with the name "Today". It works OK if there are actual lines being plotted on the chart, but if the chart is empty, then it crashes. You might think of such a chart as a template that has up to 9 lines "defined" ... you'll see the definitions if you look at the Source Data dialog box. If I provide the data in the correct location, then lines WILL be plotted. But at the moment there is no data in the defined data locations.
When it crashes I get "1004 ... Unable to get the name property of the Series class".
Since I can see the Series names in the dialog box, I presumed that VBA can too, but apparently not. Here's the basic code I'm using:
Function GetTodayLineNo() As Long
Dim SeriesNo as Long, Temp as String
For SeriesNo = 1 To ActiveChart.SeriesCollection.Count
On Error GoTo Ignore
Temp = ActiveChart.SeriesCollection(SeriesNo).Name '<--Crash here
If Left(Temp, 5) = "Today" _
Then
GetTodayLineNo = SeriesNo
GoTo Finish
End If
Ignore:
Next SeriesNo
GetTodayLineNo = 0
Finish:
End Function 'GetTodayLineNo'
An added annoyance is that the "On Error" statement is ineffective. Phffft! Any ideas??
When it crashes I get "1004 ... Unable to get the name property of the Series class".
Since I can see the Series names in the dialog box, I presumed that VBA can too, but apparently not. Here's the basic code I'm using:
Function GetTodayLineNo() As Long
Dim SeriesNo as Long, Temp as String
For SeriesNo = 1 To ActiveChart.SeriesCollection.Count
On Error GoTo Ignore
Temp = ActiveChart.SeriesCollection(SeriesNo).Name '<--Crash here
If Left(Temp, 5) = "Today" _
Then
GetTodayLineNo = SeriesNo
GoTo Finish
End If
Ignore:
Next SeriesNo
GetTodayLineNo = 0
Finish:
End Function 'GetTodayLineNo'
An added annoyance is that the "On Error" statement is ineffective. Phffft! Any ideas??