Jon,
Thanks. I know what ActiveSheet.ChartObjects.Delete does, but I don't
care because in this case, it's only one chart I need to delete. But
thanks again, because the code below is a mighty fine technique that
will come in handy in many a situation.
Since I've got your attention on the subject, perhaps you can save me
some browsing and reading time and tell me how to change the caption
of the chart window. I don't want it to show the usual [book.xls]Sheet
Chartname. I read somewhere that this can't be done until the workbook
is saved again...a pain... Is this true? I want a window because 1)
the chart looks nice and 'finished' in a window and 2) I want to take
advantage of the window caption to display the title of the chart. And
no, I don't want a usual title on the chart that will take up space.
If I can't use the window caption, I guess I will have to reconsider.
This window title will change according to what called the chart
making code...
I look forward to opening that bottle of champagne when you will
announce your new and official Jon Peltier web site
Thanks Jon.
Jon Peltier said:
Marc -
This command will remove all charts on the active sheet:
ActiveSheet.ChartObjects.Delete
You can set up your sheet so all charts on it are enabled for chart
events. In the regular code module, put this:
Dim mycharts() As New clsChartEvent
Sub Set_All_Charts()
' Enable events for all charts on a worksheet
If ActiveSheet.ChartObjects.Count > 0 Then
ReDim mycharts(ActiveSheet.ChartObjects.Count)
Dim chtObj As ChartObject
Dim chtnum As Integer
chtnum = 1
For Each chtObj In ActiveSheet.ChartObjects
Set mycharts(chtnum).EmbChart = chtObj.Chart
chtnum = chtnum + 1
Next ' chtObj
End If
End Sub
This enables all charts in the worksheet for events. Then in the
_Deactivate event procedure, you can put this to remove the chart object
that contains it, but leave any others intact:
Embedded_Chart.Parent.Delete
- Jon