I have written some code for a custom ribbon button that inserts groups of shapes, and then groups the groups.
To be able to do this more than once on the same slide, the shape names need to be renamed (or else a subsequent press of the button gets confused and tries to group up with the old shapes). So part of the code includes going back through the shapes to rename them once grouped.
Referencing the slide's Shapes collection allows you to get the top-level group. Referencing the top-level group's GroupItems takes you all the way to the bottom. There doesn't seem to be any way to access the middle level.
In the image below, the top-level group is the "Key" shape, which is accessible directly
Application.ActiveWindow.View.Slide.Shapes("Key")...
The GroupItems of that shape are the shapes that already have an underscore at the end
Application.ActiveWindow.View.Slide.Shapes("Key").GroupItems.Count
returns 8 i.e. all the shapes with the underscore at the end of the name
How do I refer to the intermediate level group names which are in the orange boxes?
This setup is required because the number of SeriesKeys is unknown when clicking the button, and choices are available for the format of the overall shape. Functionality also allows for adding into the main "Key" group later on.
So, grouping up each component seems to be the best approach.
The answer basically is to avoid using names in the first place and use a ShapeRange object. Once the shapes are stored in a variable of ShapeRange type, they can be freely renamed and then the Group method applied to the object instead of an array of the shape names. Thanks to wrbp for sending me down this path!