Search code examples
vbapowerpointoffice-2016

How can vba be used to change the vertical and horizontal positions of objects, such as word art, in powerpoint?


I have a lot of slides, each with a single word art. I wish to align the word art to the absolute centre of the slide. the code I have tried is:

Option Explicit

Sub format()

    Dim sl As Slide
    Dim ob As Object

    For Each sl In ActivePresentation.Slides

        For Each ob In sl.Shapes
            With ob.TextFrame
                 '  .TextRange.Paragraphs.ParagraphFormat.Alignment = ppAlignCenter
                 '  .TextRange.Paragraphs.ParagraphFormat.Alignment = ppAlignMiddle
                 .HorizontalAnchor = msoAnchorCenter
                 .VerticalAnchor = msoAnchorMiddle

             End With

         Next ob

    Next sl

End Sub

Solution

  • Maybe it wil help.

    Option Explicit
    
    Sub format()
    
    Dim sl As Slide
    
        For Each sl In ActivePresentation.Slides
            sl.Shapes.Range.Align msoAlignCenters, msoTrue
    
            sl.Shapes.Range.Align msoAlignMiddles, msoTrue
        Next sl
    
    End Sub