Trouble selecting chart in macro
Jeff,
You might also consider not grouping the chart and rectangle but adding the
rectangle to the chart instead of to the worksheet. The rectangle will be
owned by the chart instead of the worksheet. Thus, you can avoid
grouping/ungrouping.
Manual method:
1. Display the Drawing toolbar
2. Activate the chartobject
3. Click the rectangle icon on the toolbar and then click inside the
boundaries of the chart.
4. Position and size the rectangle as desired.
Now drag the chart around. The rectangle should be attached to (owned by)
the chart. This code will do similar to toggling the rectangle's ZOrder:
With ActiveSheet.ChartObjects(1).Chart
.Shapes(1).Visible = Not .Shapes(1).Visible
End With
Adding Rectangle to Chart Programmaticly:
Sub AddRectToChart()
Dim cht As Chart
Set cht = ActiveSheet.ChartObjects(1).Chart
cht.Shapes.AddShape 1, 100, 100, 100, 100
End Sub
Regards,
Greg
"Jeff" wrote:
I created a macro to ungroup a chart and autoshape object to edit the
autoshape. I then created a macro to regroup the chart. However, when I run
the macro, I receive an error message that "The item with the specified name
wasn't found." I tried to define a name for the object but each time the
group of objects is edited the name of the group changes (e.g., group 12,
group 13, etc.). How can I refer to this one chart/grouping in the macro?
|