Find name of Group of Selected Shape

Viewed 27

I have grouped some shapes, and if the user selects a shape within a group I want to "Select the Group" (to avoid them moving part of the group and creating a mess). How do I get the name of the "Group" if a shape within the group is selected? I have tried looking in "Activesheet", "Selection" and "Shapes" etc.

1 Answers
Sub GetShapeGroupName()

Dim s1 As Shape, s2 As Shape
Dim SelectedGroup As String

For Each s1 In ActiveSheet.Shapes
    With s1
        If .Type = msoGroup Then
            For Each s2 In .GroupItems
                If s2.Name = Selection.Name Then SelectedGroup = .Name
            Next s2
        End If
    End With
Next s1

Debug.Print SelectedGroup

End Sub
Related