Naming shapes

  • Thread starter Thread starter Ian Jones
  • Start date Start date
I

Ian Jones

Is there a workaround/explanation for the way Excel
names/references Shapes:

Open a new workbook and draw a rectangle onto a sheet.
Excel will name it "Rectangle 1"
First question - Can I rename it?

Delete "Rectangle 1".
Draw another rectangle onto the same sheet.
Excel will name it "Rectangle 2".

How can I control the naming of Shapes?
Or at least have a sequential/logical/simple(!!) way of
referencing/controlling/manipulating what could be a large
number of similar/dissimilar Shape objects.

Thank You!

Exasperat....
 
First question - Can I rename it?

Select object, type new name in Name Box (to left of formula bar) and press
Enter.

No.
 
Excel allows duplicate names:

If I have 5 shapes and name them each "Shape"..
and in code I..

ActiveSheet.Shapes("Shape").Select

...this will select the first Shape laid onto the Sheet
that was renamed "Shape"

Is there another way of referencing an individual shape?
I'm fishing for something like an array subscript.

Cheers, Ian
 
The only other property I see for identifying a shape is ID. It seems to be
read-only

Sub a()
Dim x As Shape
For Each x In ActiveSheet.Shapes
Debug.Print x.ID; x.Name
Next
End Sub

Also you can iterate through a collection of shapes like this:

Sub aa()
Dim Counter As Integer
For Counter = 1 To ActiveSheet.Shapes.Count
Debug.Print ActiveSheet.Shapes(Counter).Name
Next
End Sub
 
Back
Top