Delete chart without being prompted?

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
 
M

Mark Ivey

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
 
H

Herrick Andrews

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top