ActiveSelectionRange.GroupActiveSelectionRange.UngroupAll
Designed to break all subgroups down to a single level, And yet is doesn't work like the immediate commands executed in Draw. let me Explain.
If I have 4 objects and I select them, the above two commands executed in a macro result in a group of 4 objects. As if UngroupAll only works if you sub-groups
If I group 2 of the objects then select all and run the two commands then I have a parent group with 4 objects. The sub-group has been removed. If I then run those commands again the parent group is removed.
If I run those commands repeatedly on 4 discrete objects I end up with multiple levels of groups, the bottom level containing the 4 objects.
I want those two commands (or some other version) to take all objects in the active selection and remove all sub-groups leaving just objects and no parent group.
Thanks
It is easy to get into trouble with macros if you start doing something with selected shapes, and then further on in the macro refer to the ActiveSelection or ActiveSelectionRange. What you might think would be selected at some point in the process, well, might not be.
For grouping the selection, and then "ungrouping all", another way to do it would be this:
Sub group_then_ungroupall() Dim sGrouped As Shape Set sGrouped = ActiveSelectionRange.Group sGrouped.ungroupall End Sub
Are you willing to elaborate on why you are grouping the selection before "ungrouping all"? The only reason that comes to me would be to intentionally pull selected items from multiple layers into the active layer (by grouping) before "ungrouping all".
hywelharris said:I want those two commands (or some other version) to take all objects in the active selection and remove all sub-groups leaving just objects and no parent group.
For a relatively simple document - simple shapes, in some nested groups, on several layers - I was getting good results just using ActiveSelectionRange.ungroupall or ActiveShape.ungroupall (without grouping first). It was breaking down all of the groups and nested groups, and leaving the individual shapes on their respective layers.
Thanks John,
It was in relation to a macro you helped me with a while back. To find all instances of symbols and revert them to objects. The macro always leaves me with one group of all objects. Not a big deal as a CTRL-Shift-U sorts it but I wanted to see what was going on and why.
Sub RevertSymbolsToObjects2()Dim OrigSelection As ShapeRangeDim sh As ShapeRangeDim s As Shape, a As Shape
Dim srThisSymbolReverted As ShapeRangeDim srAllSymbolsReverted As New ShapeRange
ActiveSelectionRange.Group ActiveSelectionRange.UngroupAll Set OrigSelection = ActiveSelectionRange If OrigSelection.Count = 0 Then MsgBox "No shapes selected" Exit Sub End If For Each s In OrigSelection If s.Type = cdrSymbolShape Then OrigSelection.Remove OrigSelection.IndexOf(s) Set srThisSymbolReverted = s.Symbol.RevertToShapes srThisSymbolReverted.UngroupAll srAllSymbolsReverted.AddRange srThisSymbolReverted End If Next s OrigSelection.AddRange srAllSymbolsReverted srAllSymbolsReverted.CreateSelection
Refresh End Sub