jjf
jjf

Reputation: 25

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?

Upvotes: 1

Views: 1726

Answers (1)

Jamie Garroch - MVP
Jamie Garroch - MVP

Reputation: 2979

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

Upvotes: 1

Related Questions