How to Use VBA to Place Two Photos on Each PowerPoint Slide
Question details
The user needs to automate the placement of hundreds of images in a PowerPoint presentation, specifically arranging exactly two photos at designated coordinates on each slide using VBA.
- Product
- PowerPoint
- Device & OS
- not provided
- Scenario
- Automating the batch placement and formatting of hundreds of photos into a presentation.
- Observed behavior
- The goal is to automatically position exactly two pictures per slide at predefined Left and Top coordinates by utilizing a VBA macro loop.
Before running any VBA macros, ensure you save a backup copy of your presentation. This prevents accidental data loss or irreversible formatting overrides if the macro does not position the images exactly as expected.
Use a VBA Macro to Loop and Position Pictures
Run a custom VBA script that iterates through your slides, identifies picture shapes, and automatically sets their exact Top and Left coordinates.
This method leverages VBA code to count the picture objects on each slide. Once identified, it assigns predefined placement coordinates to the first and second picture shapes, ensuring uniform formatting across hundreds of slides.
Press Alt + F11 in PowerPoint to open the Microsoft Visual Basic for Applications (VBA) editor.
Click 'Insert' from the top menu, then select 'Module' to create a blank workspace for your macro code.
Input a VBA script that loops through each slide (using 'For Each sld In ActivePresentation.Slides'), identifies shapes that are pictures (checking 'msoPicture'), and sets their '.Top' and '.Left' properties based on whether it is the first or second picture found on that specific slide.
Close the VBA editor and press Alt + F8 to open the Macro dialog box. Select your newly created macro and click 'Run' to apply the formatting to your presentation.
Easily Manage Presentation Images with WPS Office
WPS Presentation offers seamless ways to manage, align, and format multiple pictures without strictly needing to write complex VBA code. Its intuitive interface and high compatibility with Microsoft PowerPoint make it a breeze to create photo-heavy slides, while advanced users can still leverage robust macro tools.
- 1. Open WPS Presentation: Launch WPS Office and create a new presentation or open your existing .pptx file.
- 2. Insert Multiple Pictures: Go to the 'Insert' tab, click 'Picture', and select multiple photos to bulk-add them to your presentation.
- 3. Use Alignment Tools: Select the pictures you want to arrange on a slide, navigate to the 'Picture Tools' tab, and use the 'Align' options to distribute them perfectly.
- 4. Enable VBA Support (Optional): If you already have a VBA script, WPS Office Professional provides a comprehensive VBA environment. Press Alt + F11 to open the macro editor and run your code seamlessly.

Frequently Asked Questions
Why are my pictures not moving to the correct coordinates when running the macro?
Ensure your VBA macro specifically checks the shape type (`msoPicture`) before applying the `.Top` and `.Left` properties. If the loop applies these coordinates to text boxes or slide placeholders instead of images, it will yield incorrect results.
Can I adjust the size of the photos using VBA alongside their placement?
Yes, you can also modify the `.Height` and `.Width` properties of the picture shape within the same VBA loop to ensure all inserted photos are completely uniform in size before placing them at their coordinates.
How do I find the exact Left and Top coordinates for my VBA macro?
You can manually place a picture exactly where you want it on a slide, right-click it, select 'Size and Position', and note the horizontal and vertical positions (in inches or centimeters). You will need to convert these measurements to points (1 inch = 72 points) for your VBA code.
Will my VBA macro work if I save the presentation as a standard .pptx?
No, standard `.pptx` files strip out macro code for security reasons. You must save presentations containing VBA macros as a Macro-Enabled Presentation (`.pptm`) to retain and execute the code.




