logo
search
VBA & Macro Problems

How to Create a Word VBA Macro to Insert Six Pictures Per Page

Khadija KhanKhadija Khan Oct 15, 2026 872 views

Question details

The user needs to properly set up a VBA macro that batch imports multiple images into a two-column, six-pictures-per-page document layout while resolving OS-specific file path errors.

How to Create a Word VBA Macro to Insert Six Pictures Per Page
Product
Word
Device & OS
not provided
Scenario
Automating the insertion of hundreds of photos into a structured Word document layout with space for captions using a VBA macro.
Observed behavior
The macro fails to locate the images on certain operating systems because it relies on hardcoded Windows file paths and separators, which do not function correctly on macOS.
Before you start

Ensure you have the Developer tab enabled in your Word ribbon and gather all the photos you wish to import into a single accessible local folder.

Solution 1Recommended

Adjust File Path Syntax for the Correct Operating System

Fix macro execution failures by updating the hardcoded file paths and separators to match the operating system you are actively using.

macOS and Windows utilize entirely different file system structures. Windows relies on drive letters and backslashes (e.g., C:\Images\), whereas macOS uses a unified root directory and forward slashes (e.g., /Users/username/Pictures/). If your macro throws a 'File Not Found' error, correcting the path syntax is the first step.

1
Locate the exact folder path on Mac

Open Finder, navigate to your target image folder (like Pictures), and select View > Show Path Bar from the top menu. The exact path will display at the bottom of the window.

2
Update the macro string

Press Alt + F11 to open the VBA Editor. Locate the line of code defining your image directory and replace the Windows path with your exact Mac path.

3
Adjust the path separators

Ensure that any hardcoded slashes in your file-looping logic are changed from backslashes (\) to forward slashes (/).

4
Run the updated macro

Save the VBA script and click 'Run' to verify that Word successfully locates the folder and generates the six-picture layout.

Adjust File Path Syntax for the Correct Operating System
Dynamic Path Separators: To make your VBA script universally compatible across Mac and Windows, use 'Application.PathSeparator' in your code instead of typing a hardcoded slash.
Efficient Document Formatting

Run Formatting Macros Effortlessly in WPS Office

WPS Office fully supports VBA macros, allowing you to seamlessly run your automated scripts for inserting multiple pictures per page. With excellent compatibility and a lightweight design, WPS Writer handles batch image formatting beautifully.

  1. 1. Open WPS Writer: Launch WPS Office and open a new blank document or your existing template.
  2. 2. Access the Developer Tools: Navigate to the Developer tab on the top ribbon and click on the 'VBA Editor' icon.
  3. 3. Paste your Macro Code: Insert your 6-pictures-per-page macro code into the active module.
  4. 4. Run the Script: Execute the macro, select your image directory when prompted, and watch WPS automatically arrange your layout.
Full support for running Microsoft Office VBA macros and custom scripts.Seamless compatibility with .doc, .docx, and .docm file formats.Lightweight performance, ideal for processing documents with hundreds of images.Intuitive manual layout tools if you prefer not to use code.
microsoft office alternative - wps office

Frequently Asked Questions

Why does my picture-insertion macro work on Windows but crash on a Mac?

This happens because macOS and Windows use different file path structures. Windows uses drive letters and backslashes (C:\Photos\), while macOS uses a root directory and forward slashes (/Users/name/Photos/). If your code hardcodes a Windows path, Mac Office cannot read it.

How do I structure the VBA code to fit exactly six pictures on one page?

The most reliable method is to write the VBA macro to insert a 2-column by 3-row table that spans the width and height of the page margins. The code should then loop through the image files and insert each picture into the next available table cell, applying a fixed width to keep the layout uniform.

Can I make the macro prompt me to select specific photos instead of an entire folder?

Yes. Instead of using 'msoFileDialogFolderPicker', you can update your code to use 'Application.FileDialog(msoFileDialogFilePicker)'. Be sure to set '.AllowMultiSelect = True' in the properties so you can select multiple individual image files simultaneously.