Arrange All The Pictures Of A Presentation

Share this

July 15, 2012

Arrange All The Pictures Of A Presentation

Some months ago I had to prepare a presentation with results from a series of experiments. The presentation had around 65 slides and each of them contained a picture (= chart with results). Since all slides had a similar format (title up and chart below) I thought that it will be very time consuming to manually align all these pictures. So, I just aligned one picture and then I used this VBA code to align the pictures on the rest slides.

How to do it

Step 1: Simply align only one picture of a random slide and use the code below to obtain its position and size. The picture properties will be printed on immediate window of VBA editor and will be also showed on a message box. To view immediate window, first press ALT + F11 to view the VBA editor and the press CTRL + G or click View > Immediate window on VBA editor menu.

Option Explicit

Sub PicturePositionAndSize()
   
    'Print the position and the size of the active picture
    'in immediate window and on a message box
    'By Christos Samaras

       
    'Check if the selection is a picture
    With ActiveWindow.Selection
        If .Type = ppSelectionShapes Then
            If .ShapeRange.Type = msoPicture Then
           
            'Print results in immediate window
                Debug.Print "Picture Dimensions And Size:" & vbNewLine & _
                            "Top = " & .ShapeRange.Top & vbNewLine & _
                            "Left = " & .ShapeRange.Left & vbNewLine & _
                            "Height = " & .ShapeRange.Height & vbNewLine & _
                            "Width = " & .ShapeRange.Width
           
            'Show results on a message box
                MsgBox "Picture Dimensions And Size:" & vbNewLine & _
                        "Top = " & .ShapeRange.Top & vbNewLine & _
                        "Left = " & .ShapeRange.Left & vbNewLine & _
                        "Height = " & .ShapeRange.Height & vbNewLine & _
                        "Width = " & .ShapeRange.Width, vbInformation
            End If
       
        'In case the selection is NOT a picture warn the user
        Else
            MsgBox "Please select a picture first!", vbCritical
        End If
       
    End With
   
End Sub

Step 2: Use the properties you obtained from the previous step to align all the pictures of the presentation. 
Option Explicit

Sub ArrangePictures()
   
    'Arrange all the pictures of the active presentation
    'By Christos Samaras

    Dim i As Integer
    Dim j As Integer
   
    'For each slide in presentation
    For i = 1 To ActivePresentation.Slides.Count
       
        With ActivePresentation.Slides(i)
       
            'For each shape in active slide
            For j = 1 To .Shapes.Count
           
                With .Shapes(j)
               
                    'if the shape is picture determine its position and size
                    If .Type = msoPicture Then
                   
                    'Change these properties accroding to your own needs
                        .Top = 87.84976
                        .Left = 33.98417
                        .Height = 422.7964
                        .Width = 646.5262
                    End If
                   
                End With
               
            Next j
           
        End With
       
    Next i

End Sub
Preview it on slideshare

Here is the presentation before using the VBA code.  
Here is after running the macros.

Sample file

This sample presentation contains the VBA code described above. The pictures on every slide are not aligned.

1) So, align the picture on the first slide according to your own needs and then press ALT + F8. The macro menu will pop up. Select  the “PicturePositionAndSize” macro and then press the Run button. A message box will pop up containing the picture dimensions. You can either write down the values (on notepad for example) or you can press ALT + F11 to view them on immediate window of VBA editor. Afterwards, at the VBA editor, copy these values to the other sub (“ArangePictures”). You will have to replace the green values with your own values:

.Top = 87.84976
.Left = 33.98417
.Height = 422.7964
.Width = 646.5262

2) If you have successfully completed the previous procedure, you can then press ALT + F8. From the macro menu select the “ArangePictures” macro and then press the Run button. The macro will format all the pictures of the presentation based on the format of the first picture.

Note that since I have already done the work described in 1, you can start from the  procedure 2.

Download it from here

This file can be opened with Office 2007 or newer.

Page last modified: January 6, 2019

Christos Samaras

Hi, I am Christos, a Mechanical Engineer by profession (Ph.D.) and a Software Developer by obsession (10+ years of experience)! I founded this site back in 2011 intending to provide solutions to various engineering and programming problems.

Christos E. Samaras

{"email":"Email address invalid","url":"Website address invalid","required":"Required field missing"}
Add Content Block
>