Resize Pictures During A PowerPoint Presentation

Share this

September 14, 2011

Last updated: 30/09/2017, 2 min read

Resize Pictures During A Presentation

Introduction


During a presentation, there is sometimes the need for resizing a picture. For example, due to limited slide space, you might have put a small image that you would like to enlarge to show some details. Well, with few lines of VBA code this is no longer a problem! By just clicking on the selected picture you can enlarge it, and, then, with another click, you can resize it back to its original size. In this way, no additional slides are required!

How to do it


Prepare your slides as usual (put your pictures and text). Then follow the  procedure below, which involves six steps:
Step 1: Use the code below to determine the name of the images, as well as their height and width. You can see the result of this macro in the immediate window (use CTRL + G to view it, if it is not visible) of the VBA editor (ALT + F11 to see the editor). In this example the results were:
Name = Picture 4, Height = 129.2741, Width = 215.457
Name = Picture 5, Height = 129.2741, Width = 215.457
Option Explicit

Sub ShapeNames()

'-------------------------------------------------------------------
'Loops through all of the shapes of slide 1 and prints their names,
'heights and widhts in the immediate window of VBA editor.

'Written By: Christos Samaras
'Date: 14/09/2011
'Last Updated: 23/11/2013
'E-mail: [email protected]
'Site: https://myengineeringworld.net/////
'-------------------------------------------------------------------

'Declaring the necessary variable.
Dim i As Integer

'If you have other slide, change the number in the parenthesis according to your needs.
With ActivePresentation.Slides(1)
For i = 1 To .Shapes.Count
Debug.Print "Name = " & .Shapes(i).Name & ", Height = " & _
.Shapes(i).Height & ", Width = " & .Shapes(i).Width
Next i
End With

End Sub

Step 2: Manually resize the pictures until you feel satisfied with their size and repeat step 1. In this example the new sizes were:
Name = Picture 4, Height = 450, Width = 550
Name = Picture 5, Height = 450, Width = 550
Press the undo button to discard the new sizes and switch the images back to their original size.
Step 3: Use the code below to resize the left picture.
Sub ResizeLeftPicture()

'--------------------------------------------------
'The macro resizes the left picture.

'Written By: Christos Samaras
'Date: 14/09/2011
'Last Updated: 23/11/2013
'E-mail: [email protected]
'Site: https://myengineeringworld.net/////
'--------------------------------------------------

'Declaring the necessary variable.
Dim oPicture As Shape

'If you have other slide or shape, change the number according to your needs.
Set oPicture = ActivePresentation.Slides(1).Shapes("Picture 4")

'Change the width and height of the picture according to your needs.
'The next line checks the shape's size. If the size is "large"
'the code shrinks the picture, otherwise it enlarges the picture.
With oPicture
If .Height = 450 Or .Width = 550 Then
'Shrink the picture.
.Height = 141.748
.Width = 215.457
Else
'Enlarge the picture.
.Height = 450
.Width = 550
End If
'Bring the resized picture forward (above other pictures or text).
.ZOrder msoBringForward
End With

End Sub
Step 4: With the code below you can change the size of the right image. The code is slightly different than the previous one due to the introduction of the Right variable. The shapes don’t have a right property – as they have left, top, height and width property, so to align the picture in the correct position, we have to use this intermediate variable.

Sub ResizeRightPicture()

'--------------------------------------------------
'Risizes the right picture.

'Written By: Christos Samaras
'Date: 14/09/2011
'Last Updated: 23/11/2013
'E-mail: [email protected]
'Site: https://myengineeringworld.net/////
'--------------------------------------------------

'Declaring the necessary variables.
Dim oPicture As Shape
Dim Right As Double

'If you have other slide or shape, change the number according to your needs.
Set oPicture = ActivePresentation.Slides(1).Shapes("Picture 5")

'Change the width and height of the picture according to your needs.
'The next line checks the shape's size. If the size is "large"
'the code shrinks the picture, otherwise it enlarges the picture.
With oPicture
Right = .Left + .Width
If oPicture.Height = 450 Or oPicture.Width = 550 Then
'Shrink the picture.
.Height = 141.748
.Width = 215.457
.Left = Right - .Width
Else
'Enlarge the picture.
.Height = 450
.Width = 550
.Left = Right - .Width
End If
'Bring the resized picture forward (above other pictures or text).
.ZOrder msoBringForward
End With

End Sub

Step 5: Select the slide that contains the pictures you want to resize and then select the left picture. Afterwards:

Insert Tab (Ribbon) -> Action -> Mouse Click Tab -> Run Macro -> Select “ResizeLeftPicture”.
Step 6: Finally, select the right picture and then: 

Insert Tab (Ribbon) -> Action -> Mouse Click Tab -> Run Macro -> Select “ResizeRightPicture”.

Demonstration video


The short video below shows how the two pictures are being resized after using the above macros.

In the downloads section below you will find the PowerPoint file that contains the code that analyzed above. The two figures were found on a General Electric paper with the title: Dry Low NOx Combustion Systems for GE Heavy-Duty Gas Turbines.


Downloads


Download

The file can be opened with PowerPoint 2007 or newer. Please enable macros before using it.


Read also


Export All Excel Charts To PowerPoint  Export Excel Ranges As PowerPoint Tables 

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
>