How to Bulk Insert Images into Multiple Word Table Cells using VBA
Question details
The user needs to automate the process of inserting photos in bulk into 50 to 60 two-cell or three-cell tables within a Word report template.
- Product
- Microsoft Word
- Device & OS
- not provided
- Scenario
- Populating a large report template that requires dozens of images to be placed into specific table cells.
- Observed behavior
- Inserting images manually into 50-60 tables is extremely time-consuming. The goal is to automate the workflow using a VBA macro to iterate through tables and insert photos from a folder.
Ensure all your target images are collected in a single folder on your computer and renamed in a sequential numeric order (e.g., 1.jpg, 2.jpg) so the script can process them consecutively.
Use a VBA Macro to Automate Bulk Image Insertion
Running a custom VBA script allows you to loop through all tables in your document and automatically insert sequentially named images into the correct cells.
This solution relies on iterating through the document's Tables collection. The code will target each cell in succession and insert the next sequential image from your specified local directory.
Place all images in a dedicated folder and ensure they are sequentially named (1.jpg, 2.jpg, etc.). Take note of the exact folder directory path on your computer.
Open your Word report template and press ALT + F11 on your keyboard to launch the Microsoft Visual Basic for Applications (VBA) window.
Click 'Insert' from the top menu, select 'Module', and paste your specific bulk-insertion macro code into the blank code window.
Locate the string in the code that defines the image folder directory. Update it to match your exact folder path and verify that the file extension (e.g., .jpg or .png) matches your actual image files.
Press F5 or click the 'Run' button on the top toolbar. The macro will automatically loop through your document's tables and populate the cells with your photos.
Streamline Your Reports with WPS Writer
WPS Writer offers an intuitive interface and robust tools for handling extensive report templates, large numbers of images, and complex table layouts. It allows for seamless editing and formatting, making document automation and image management highly efficient.
- 1. Open your report template: Launch WPS Writer and open your .docx report template.
- 2. Set up your tables: Navigate to the Insert tab, create or modify your 2-cell/3-cell tables, and adjust Table Properties to set fixed column widths.
- 3. Bulk insert pictures: Click Insert > Picture, select all your required sequential images from your folder, and insert them into the document workspace.
- 4. Arrange within cells: Quickly drag and drop the inserted images into their respective table cells using WPS Writer's fluid object handling.

Frequently Asked Questions
Can I insert multiple images into a Word table without using VBA?
Yes, you can go to Insert > Pictures, select multiple image files, and insert them all at once. However, the program will insert them consecutively at your cursor's location, meaning you will still need to manually drag each one into its respective table cell.
Why is my VBA macro throwing a 'File Not Found' error?
This error typically occurs if the file path specified in your VBA code is incorrect, or if the file extensions written in the code (such as .png instead of .jpg) do not perfectly match the actual files in your folder.
How can I prevent the inserted images from breaking my table layout?
Select your table, right-click and choose Table Properties. Under the Table tab, click Options and uncheck 'Automatically resize to fit contents'. Alternatively, you can include specific width and height constraint lines directly in your VBA script.
Will the macro work properly if I join multiple tables together?
Yes. VBA macros typically iterate through the 'Tables' collection as recognized by the document. If you join several smaller tables into one large table, the macro will treat it as a single table entity and loop through its individual cells accordingly.




