VBA Can someone explain this for me

ActiveSelectionRange.Group
ActiveSelectionRange.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

Parents
No Data
Reply
  • 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".

    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.

Children