Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Statement OK in Macro but not in code? 1

Status
Not open for further replies.

JFF

Programmer
May 6, 2001
13
US
In Excel 2002, I have code that creates an embedded Chart named "Results" on a sheet. It's there. When I record a macro and delete the chart, the macro has this line in it at the beginning:

ActiveSheet.ChartObjects("Results").Activate

When I run my own same code and put the chart back in the sheet and then put exactly that same line in my code, I get this error:

Run-time error 1004
Unable to get the ChartObjects property of the Worksheet class.

Please help,
John
 
Hi JFF,

You don't have to activate the Chart to delete it, so try something like this:

Sub KillChart()
If ActiveWorkbook.ActiveSheet.Shapes.Count > 0 Then
For Each Shp In ActiveWorkbook.ActiveSheet.Shapes
If Shp.Name = "Results" Then Shp.Delete
Next Shp
End If
End Sub
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top