Can someone tell me how to check and see if a graph exists on a
worksheet so that I can either add another series to it or create a new
chart. In other words, if a chart already exists, I only want to add a
series to it. However, if the chart doesn't exist, I want to create
one. Unfortunately, I don't know the code required to check if a graph,
such as "Chart 1" exists. Can anyone help? Thanks!
Paul
This is what I used with XL2000, this code checks for a chart on each sheet
in the active workbook.
I tested the sheet type in case the chart was on a chart sheet instead of
embedded in a worksheet.
Option Explicit
Sub ChartCheck()
Dim msg As VbMsgBoxResult
Dim n As Integer
On Error Resume Next
For n = 1 To Sheets.Count
Sheets(n).ChartObjects(1).Select
If Err <> 0 And Sheets(n).Type <> 4 Then
msg = MsgBox("No chart here!", vbOKOnly, Sheets(n).Name)
Else
msg = MsgBox("Chart already exists!", vbOKOnly, Sheets(n).Name)
End If
Err = 0
Next n
End Sub
Mike
"Paul Alappat" <pala...@cisco.com> wrote in message
news:39A6DA4...@cisco.com...
"Michael" <medi...@hotmail.com> wrote in message
news:i2Gp5.810$HQ5.3...@news.uswest.net...
> "Michael" <medi...@hotmail.com> wrote in message
> news:i2Gp5.810$HQ5.3...@news.uswest.net...
> > I tested the sheet type in case the chart was on a chart sheet instead
of
> > embedded in a worksheet.
If Sheets(n).Type = 4 then Sheets(n) is a chart sheet.
There is probably an alpha code for this like x1ChartSheet but I did not
find it anywhere
Embedded charts are Worksheet objects and Chart Sheets are Workbook objects.
Chart Sheets do not contain the ChartObject collection, therefore
Sheets("Chart Sheet").ChartObjects(1).Select
would produce an error.
Check out "The Chart object model" pp 472-473 in John Walkenbach's Excel
2000 Power Programming with VBA for more info
Mike
"Mark Roth" <mr_mar...@hotmail.com> wrote in message
news:FP3q5.212368$8u4.2...@news1.rdc1.bc.home.com...
Paul