Others

How to Align One or Two Pictures per Slide using PowerPoint VBA

Chanuka GeekiyanageChanuka Geekiyanage Nov 3, 2026 868 views

Question details

The user needs a VBA macro to automatically format the layout of slides based on the number of images present, specifically to center a single image or place two images side-by-side.

How to Align One or Two Pictures per Slide using PowerPoint VBA
Product
PowerPoint
Device & OS
not provided
Scenario
Automating the sizing and alignment of pictures across multiple presentation slides to maintain a consistent layout.
Observed behavior
The user seeks an automated way to position items instead of manually dragging and resizing pictures on every slide.
Before you start

Ensure that the Developer tab is enabled in your PowerPoint ribbon so you can access the VBA Editor. It is also highly recommended to save a backup copy of your presentation before running any new macros.

Solution 1Recommended

Create a VBA Macro to Count and Align Pictures

Use a VBA script to iterate through the shapes on each slide, count the pictures, and dynamically update their Left, Top, Width, and Height properties to achieve the desired layout.

The logic of the macro involves looping through each slide and counting how many shapes are categorized as pictures (including those inside placeholders).

If exactly one picture is found, the macro calculates the center coordinates of the slide and positions the picture there. If two pictures are found, it divides the slide width by two, placing the first picture on the left half and the second on the right half, adjusting their sizes proportionally.

1
Open the VBA Editor

Press Alt + F11 on your keyboard to open the Microsoft Visual Basic for Applications window.

2
Insert a New Module

Click 'Insert' in the top menu and select 'Module'. This will open a blank text window where you can write your macro.

3
Write the Alignment Logic

Create a subroutine that loops through 'ActivePresentation.Slides'. Inside that loop, count the shapes where 'Shape.Type = msoPicture'. Store these shapes in an array or collection.

4
Apply Position Coordinates

Add an 'If...Else' statement based on the picture count. For 1 picture, set its '.Left' and '.Top' properties to center it based on 'ActivePresentation.PageSetup.SlideWidth' and 'SlideHeight'. For 2 pictures, set the first picture's '.Left' to 0, and the second picture's '.Left' to half the slide width.

5
Run the Macro

Close the VBA editor, go to the Developer tab, click 'Macros', select your newly created macro, and click 'Run'.

Create a VBA Macro to Count and Align Pictures
Placeholder Compatibility: Make sure your VBA script also checks for 'msoPlaceholder' types that contain pictures if your presentation relies heavily on slide master layouts.
Efficient Presentation Design

Easily Align Pictures in WPS Presentation

While VBA macros are powerful, WPS Presentation offers intuitive, built-in smart alignment and distribution tools that let you perfectly center or arrange multiple pictures side-by-side with just a few clicks.

  1. 1. Insert Your Pictures: Open your slide in WPS Presentation and insert the pictures you want to arrange.
  2. 2. Select Multiple Images: Hold down the Ctrl key and click on each picture to select them simultaneously.
  3. 3. Use Alignment Tools: Navigate to the 'Picture Tools' tab on the ribbon. Click the 'Align' button and choose 'Align Middle' and 'Distribute Horizontally' to instantly arrange two pictures side-by-side.
  4. 4. Center a Single Image: For a single image, select it, click 'Align', and choose both 'Align Center' and 'Align Middle' to place it perfectly in the center of the slide.
Fully compatible with Microsoft PowerPoint (.pptx) formats and layoutsSmart alignment guides and built-in distribution toolsSupports advanced VBA macros for heavy automation tasksLightweight, fast, and free to use
microsoft office alternative - wps office

Frequently Asked Questions

How do I enable the Developer tab to use VBA?

Go to File > Options > Customize Ribbon. In the right pane, locate and check the box next to 'Developer', then click OK. The Developer tab will now appear on your ribbon.

Can a VBA macro automatically resize the pictures to fit the slide?

Yes. By modifying the .Width and .Height properties of the shape object in your VBA code, you can force the pictures to scale up or down to fit specific dimensions before setting their .Left and .Top properties.

Why is my PowerPoint macro not running?

Macro execution might be restricted by your security settings. Go to File > Options > Trust Center > Trust Center Settings > Macro Settings, and choose 'Disable all macros with notification' so you can manually approve the macro, or save your file in a Trusted Location.