-
Solved: Delete Embedded Charts
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
-
try this:
[VBA]
ActiveWorkbook.Charts.Delete
[/VBA]
-
[VBA]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
[/VBA]
MVP (Excel 2008-2010)
Post a workbook with sample data and layout if you want a quicker solution.
To help indent your macros try Smart Indent
Please remember to mark threads 'Solved'
-
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
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules