We start with some Excel 2007 VBA to draw a shape of several parts, and to group those parts. Somewhat condensed for legibility, the code so far looks like:
Set sh1 = .shapes.AddPolyline(...)
Set sh2 = .shapes.AddShape(Type:=msoShapeRectangle, Left:=...)
sh1.Name = "Part1"
sh2.Name = "Part2"
sh1.Fill.ForeColor.RGB = ...
sh1.Line.Visible = msoFalse
...
So far, so good.
Then
shapes.Range(Array("Part1", "Part2")).Group
That works fine (even if I can't explain why it has a lower-case "s" on "shapes"). But then I run the code again and Excel reports
> Run-time error '1004':
> Grouping is disabled for the selected shapes.
My guess is that Excel 2007 is attempting to group the first-made items with names "Part1" and "Part2", which are already part of a group. Hence the failure.
Please, is it possible to specify the Shapes.Range(Array(...)) using the shape pointers (sh1 and sh2) rather than the names?
Thank you.
Bookmarks