Search code examples
vbapowerpointgroup

How can I change qualities (text, fill, etc.) of a grouped object?


My question is generic because I've run into this multiple times for other aspects of an object.

I have a group of blocks that each contain a date (think of a calendar). I am using macros to revise the date based on the current date. However I need to have those blocks grouped so I can animate the collection together.

I believe I have a long workaround, but it involves code to ungroup, make the change, regroup, reconfigure animation, reassign the trigger, etc.

It seems the simple solution would be to directly modify the text of the grouped object if possible.


Solution

  • Grouped shapes can be accessed via the parent shape's GroupItems property.

    Eg for a slide containing a single group consisting of several rectangles:

    Sub Tester()
        Dim s As Shape, e As Shape
        
        With ActivePresentation.Slides(1)
            For Each s In .Shapes
                Debug.Print "--- " & s.Name & " ---"
                
                'loop group items...
                For Each e In s.GroupItems
                    Debug.Print e.Name
                    e.TextFrame.TextRange.Text = "OK"
                Next e
                
                'address a specific sub-shape
                With s.GroupItems("Rectangle 4").TextFrame.TextRange
                    .Text = "Hi"
                End With
                
            Next s
        End With
    End Sub