The following macro generates a textbox on top of the y-axis to show the units. I use a textbox instead of the inbuilt legend format because it's more flexible.
ActiveChart.Shapes.AddTextbox(msoTextOrientationHorizontal, 0, 0, 80, 20).Select
With Selection.ShapeRange(1).TextFrame2.TextRange
.Characters.Text = "[Units]"
End With
I want to add a conditional before this block so that the code stops if the textbox already exists. How can I 1) count how many textboxes there are in a graph (not in the whole sheet) and 2) check whether there is a textbox of the same dimension and position in the graph?
Perhaps something like the following, but somehow restricted to textboxes?
If ActiveSheet.Shapes.Count > 0 Then
...
If ActiveSheet.Shapes(ActiveChart.Parent.Name).Count > 0 Then
...


ActiveSheet.Shapes(ActiveChart.Parent.Name)and maybe usetypenameto check