Search code examples
vbapowerpoint

How to align pictures on different slides using a macro in Power Point


I have the following macro that aligns 1 selected picture at a time in Power Point:

Sub Align()
      With ActiveWindow.Selection.ShapeRange 
              .Left = 50
              .Top = 100
      End With
End Sub

This code works if I run the macro on a selected picture in a slide.

But how can I run this script for each picture of all slides?


Solution

  • This will do that for you Jose:

    ' PowerPoint VBA to reposition all pictures in all slides in a deck
    ' Written by Jamie Garroch of YOUpresent Ltd.
    ' http://youpresent.co.uk/
    
    Option Explict
    
    Sub RepositionAllPictures()
      Dim oSld As Slide
      Dim oShp as Shape
      For Each oSld in ActivePresentation.Slides
        For Each oShp in oSld.Shapes
          If oShp.Type = msoPicture Then RepositionShape oShp
          If oShp.Type = msoPlaceholder Then
            If oShp.PlaceholderFormat.ContainedType = msoPicture Or _
               oShp.PlaceholderFormat.ContainedType = msoLinkedPicture Then _
                 RepositionShape oShp
          End If
        Next
      Next
    End Sub
    
    Sub RepositionShape(oShp As Shape)
      oShp.Left = 50
      oShp.Top = 100
    End Sub