Naming shapes

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....
 
J

Jim Rech

First question - Can I rename it?

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

No.
 
I

Ian Jones

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
 
J

Jim Rech

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
 

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