![]() |
Names of Grouped Shapes
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 |
Names of Grouped Shapes
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.) Mogwai wrote: 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 -- Dave Peterson |
Names of Grouped Shapes
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. |
Names of Grouped Shapes
Maybe not. Maybe someone who has xl97 (or remembers xl97 better than I do) will
chime in. Mogwai wrote: 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. -- Dave Peterson |
Names of Grouped Shapes
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 Mogwai wrote: 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. -- Dave Peterson |
Names of Grouped Shapes
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. Peter T wrote: 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 Mogwai wrote: 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. -- Dave Peterson -- Dave Peterson |
Names of Grouped Shapes
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 "Dave Peterson" wrote in message ... 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. Peter T wrote: 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 Mogwai wrote: 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. -- Dave Peterson -- Dave Peterson |
Names of Grouped Shapes
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. |
Names of Grouped Shapes
Ah, but you remembered that it could be done.
So together, we have one mind (and one mind disappearing???). Peter T wrote: 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 "Dave Peterson" wrote in message ... 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. Peter T wrote: 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 Mogwai wrote: 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. -- Dave Peterson -- Dave Peterson -- Dave Peterson |
Names of Grouped Shapes
Ah, but you remembered that it could be done. So together, we have one mind (and one mind disappearing???). :-) Mine has a habit of going on vacation without telling me which amounts to disappearing, and leaving me to do all the work by myself ! Regards, Peter T |
Names of Grouped Shapes
The voices in my head tell me what to do. When one goes way, it's just a little
be less noisy! <vbg Peter T wrote: Ah, but you remembered that it could be done. So together, we have one mind (and one mind disappearing???). :-) Mine has a habit of going on vacation without telling me which amounts to disappearing, and leaving me to do all the work by myself ! Regards, Peter T -- Dave Peterson |
Names of Grouped Shapes
LOL !!!
Regards. Peter T Dave Peterson wrote: The voices in my head tell me what to do. When one goes way, it's just a little be less noisy! <vbg Peter T wrote: Ah, but you remembered that it could be done. So together, we have one mind (and one mind disappearing???). :-) Mine has a habit of going on vacation without telling me which amounts to disappearing, and leaving me to do all the work by myself ! Regards, Peter T -- Dave Peterson |
All times are GMT +1. The time now is 07:49 PM. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com