Names of Grouped Shapes

M

Mogwai

Hi there,

I have quite a few groups with the same number *and name* of Shapes
within, exactly like so:

"Group 1" has "Shape 1", "Shape 2", "Shape 3"
"Group 2" has "Shape 1", "Shape 2", "Shape 3"

I assigned Daves code (below) to each and every Shape. However, if I
click on a Shape in "Group 2" Excel reports that the Shape is part of
"Group 1"

I assume this is due to Shapes in "Group 2" having the same name as
Shapes in "Group 1", but is there any way I can get the correct Group
name for the Shape within?

Thanks

Sub TestSub()
Dim myShape As Shape
Dim i As Long
Dim FoundIt As Boolean
Dim itemCount As Long

FoundIt = False
For Each myShape In ActiveSheet.Shapes
itemCount = 0
On Error Resume Next
itemCount = myShape.GroupItems.Count
On Error GoTo 0
If itemCount > 0 Then
For i = 1 To myShape.GroupItems.Count
If myShape.GroupItems(i).Name = Application.Caller Then

MsgBox myShape.GroupItems(i).Name & vbLf &
myShape.Name
myShape.Select
FoundIt = True
Exit For
End If
Next i
If FoundIt Then
Exit For
End If
Else
If myShape.Name = Application.Caller Then
myShape.Select
Exit For
End If
End If
Next myShape
End Sub
 
D

Dave Peterson

Are you using xl97?

If I recall correctly, you could give different shapes the same name in that
version.

Anyway, I'm using xl2003 and I can't do that anymore.

My suggestion would be to give each shape a nice unique name.

(but maybe someone will have a better suggestion.)
 
M

Mogwai

Hi Dave,

Yes, I'm using xl97.

I thought there may be an index behind a shape/group that could be
returned, or referenced instead of the .name, but if you are at a loss
then I'm totally fugged! :)

Thanks for having a look and for the aforementioned code.
 
D

Dave Peterson

Maybe not. Maybe someone who has xl97 (or remembers xl97 better than I do) will
chime in.
 
P

Peter T

Maybe someone who has xl97 (or remembers xl97 better than I do) will
chime in.

Ding-dong

Even in XL97 I don't think you can directly name duplicates (vaguely recall
an msDrawings update for Office97, maybe that changed things). However, in
XL97, XL2k and I think(?) later versions duplicate shape names can be
created like this:

1. Rename some shapes from their original default names
2. Select these shapes, copy & paste
4. Group the pasted selection (without unselecting after pasting)

Ungroup and compare names.

Mogwai - I'm sure you're not going to resolve your problem unless all your
shapes have unique names. Application.caller returns the name of the
OnAction shape that called the macro. Confusion if duplicate names.

Try something like this to rename them

Sub ReNameGpItems()
Dim obGI As Object '
Dim grpObj As GroupObject

For Each grpObj In ActiveSheet.GroupObjects
i = i + 1
For Each obGI In grpObj.ShapeRange.GroupItems
s = "Gp" & Format(i, "00") & obGI.Name
obGI.Name = s
Next
Next
End Sub

Above assumes shapes are already grouped but only one level of grouping. For
multiple group layers would need a recursive type function.

Regards,
Peter T
 
D

Dave Peterson

I used xl2003 and I could have the same names for different shapes if I renamed
them from their default names before I copied.

Thanks for the reminder.
 
P

Peter T

I'm sure, I mean really sure, when I tested before posting it was necessary
to group the (renamed) pasted shapes to end up with duplicate names.

But it's as simple as you say, merely copy / paste renamed shape(s) gives
duplicate names.

My mind must be playing tricks on me!

Regards,
Peter T
 
M

Mogwai

Thanks guys!

I tried creating some shapes, renaming them, copying them, grouping the
copy (without unselecting after pasting), then viewing the names after
ungrouping. The original and copies have the same name. I expect Excel
keeps a unique reference for shapes with the same name, but it won't
tell me then I'll have to name them all uniquly.

Thank you for the rename code (that would have been my next request:),
I'll give that a go.

Thanks again.
 
D

Dave Peterson

Ah, but you remembered that it could be done.

So together, we have one mind (and one mind disappearing???).

Peter said:
I'm sure, I mean really sure, when I tested before posting it was necessary
to group the (renamed) pasted shapes to end up with duplicate names.

But it's as simple as you say, merely copy / paste renamed shape(s) gives
duplicate names.

My mind must be playing tricks on me!

Regards,
Peter T
 

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