Hello, all.
Once again I am running into something that is probably easy, but just cannot figure it out. A group shape is treated as a Shape by VBA. We can set its parameters with the same commands that are used with simple shapes. Let us pretend our selected shape is a group and do this:
Sub GroupTrouble() Dim S As Shape Set S = ActiveSelectionRange.Shapes.First S.Outline.SetProperties 1, , CreateRGBColor(255, 0, 0) End Sub
That works just fine (as well as most simple shape commands - fill, movement, rotation etc), but this:
Sub GroupTrouble() Dim S As Shape Set S = ActiveSelectionRange.Shapes.First Debug.Print S.Outline.Color.RGBGreen End Sub
Throws an error. We cannot get settings from a group as from a shape.
In my case the important options are outline colors and the ability to do IsOnCurve checkups. I have done some functions that go through the subshapes. But, for example, CreateBoundary creates an object that is already inside the group and that is super annoying. Same with other functions.
Any help with this will be greatly appreciated.
In the first example, the properties are propagated to all shapes in the shape group. The shape group itself doesn't hold these properties. If every shape in the group has the same properties, you could simply ask for the first shape in the group. Like "S.Shapes.First.Outline.Color.RGBGreen"
...oh, I didn't read to the end.
To bring the a shape out of the group, try the follwing:
Dim s As Shape, gs As ShapeSet gs = ActiveShape ' The groupShapeSet s = gs.CreateBoundary(0, 0)s.OrderFrontOf gs
Wow, I would never have imagined that ordering something in front of the group would actually separate it from the group. Thanks a lot! This is already super helpful.
Wonder if it is still somehow possible to get the properties like CorelDRAW shows them ("Several outlines" if different, RGB(0,0,0) if same, for example) from grouped objects right away.
Joe said:Wow, I would never have imagined that ordering something in front of the group would actually separate it from the group.
I think that it works the other way around, too, i.e., that you can use ordering to move an object into an existing group.
I do that in one of my macros that allows two shapes to be "swapped" - exchanging their positions on the page, and their places in the stacking order.
Joe,
Here is also some code that Alex shared years ago. It shows a couple of good things. I hope you find it useful. :-)
Public Sub ExtractSelectedFromGroup() Dim sObj As Shape Dim sGroup As Shape Set sObj = ActiveShape If sObj Is Nothing Then MsgBox "Nothing selected", vbCritical Exit Sub End If Set sGroup = sObj.ParentGroup If sGroup Is Nothing Then MsgBox "Selected object is not part of a group", vbCritical Exit Sub End If If sGroup.Shapes.Count < 3 Then ' Only two (or less) objects in a group. ' Should just ungroup everything sGroup.Ungroup Else ' Extract the object and put in in front of the group sObj.OrderFrontOf sGroup End If sObj.CreateSelection End Sub