Delete chart without being prompted?

  • Thread starter Thread starter Herrick Andrews
  • Start date Start date
H

Herrick Andrews

Is there a way to delete a chart object via VBA code without it prompting me
if I really want to delete it? If I change the location of the chart so
it's embedded in a worksheet, and then delete it, I don't get prompted. But
I can't do that. I need to delete the chart while it's its own chart sheet
(not embedded in a worksheet). I created the chart programmatically.

The following two lines of code cause the problem every time for me.

Sub AddDeleteChartTest()
Dim c As Excel.Chart

Set c = Excel.Charts.Add

c.Delete ' I get a DialogBox saying "Data may exist in the sheet(s)
selected for deletion. To permanently delete the data, press Delete."
End Sub
 
See if this will work...

Mark Ivey


Sub AddDeleteChartTest()
Dim c As Excel.Chart

Set c = Excel.Charts.Add

Application.DisplayAlerts = False

c.Delete

Application.DisplayAlerts = True

End Sub
 
Did the trick!! Thanks!!


Mark Ivey said:
See if this will work...

Mark Ivey


Sub AddDeleteChartTest()
Dim c As Excel.Chart

Set c = Excel.Charts.Add

Application.DisplayAlerts = False

c.Delete

Application.DisplayAlerts = True

End Sub
 
Back
Top