+ Reply to Thread
Results 1 to 12 of 12

Names of Grouped Shapes

  1. #1
    Mogwai
    Guest

    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


  2. #2
    Dave Peterson
    Guest

    Re: 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

  3. #3
    Mogwai
    Guest

    Re: 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.


  4. #4
    Dave Peterson
    Guest

    Re: 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

  5. #5
    Peter T
    Guest

    Re: 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




  6. #6
    Dave Peterson
    Guest

    Re: 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

  7. #7
    Peter T
    Guest

    Re: 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" <[email protected]> wrote in message
    news:[email protected]...
    > 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




  8. #8
    Mogwai
    Guest

    Re: 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.


  9. #9
    Dave Peterson
    Guest

    Re: 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" <[email protected]> wrote in message
    > news:[email protected]...
    > > 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

  10. #10
    Peter T
    Guest

    Re: 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



  11. #11
    Dave Peterson
    Guest

    Re: 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

  12. #12
    Peter T
    Guest

    Re: 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




+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1