PDA

View Full Version : Solved: Delete Embedded Charts



d4vem
08-15-2006, 07:02 AM
I have tried to find a solution to the following problem without much success.

I have an application that creates a number of charts each time it is run. What I need to do is delete any charts that currently exist from the previous time it was run. I could re name each new chart when it is created but I am not really bothered about the charts name I just want to delete any existing charts and let Excel default the name.

The code I have is;

Sub delete_charts()
Dim graph As Excel.Chart
For Each graph In ThisWorkbook.Charts
graph.Delete
Next
End Sub

It runs without erroring but fails to delete any existing charts

Any help would be much appreciated

austenr
08-15-2006, 08:00 AM
try this:




ActiveWorkbook.Charts.Delete

mdmackillop
08-15-2006, 09:50 AM
Sub DeleteAllCharts()
Dim sh As Worksheet
Application.DisplayAlerts = False
'Delete chart sheets
ActiveWorkbook.Charts.Delete
'Delete embedded charts
For Each sh In Worksheets
sh.ChartObjects.Delete
Next
Application.DisplayAlerts = True
End Sub

d4vem
08-15-2006, 10:38 AM
Thanks Malcolm,

Yet again you come up trumps.

Thanks very much for the solution, it's much appriecated I have tried all day to get an answer before posting an enquiry