Deleting all charts in workbook or worksheet

D

dushkin

Hi,
I am trying to delete all charts I have in my wotrkbook.

I tried this code:

Charts charts = a_wb.GetCharts();
while (charts.GetCount() > 0) {
_Chart chrt = charts.GetItem((COleVariant)((short)1));
chrt.Delete();
}

and many more algorithms...

Nothing works for me!!!

Can someone help please???

Thanks.
 
A

Alan Moseley

Try the following:-

Public Sub delcharts()
Dim ws As Worksheet
Dim cht As Object
If ThisWorkbook.Charts.Count > 0 Then
'The next line deletes all chart sheets
ThisWorkbook.Charts.Delete
End If
'The code below removes all embedded charts
For Each ws In ThisWorkbook.Sheets
For Each cht In ws.ChartObjects
cht.Delete
Next
Next
End Sub
 
A

AnAmericanInDublin

Thanks for that. I wasn't looking to delete all the charts, just looking for
a handy way to enumerate all the charts in a workbook.

Cheers!
 
Top