How to Add Multiple Pictures and Captions Dynamically in Word VBA
Question details
The user needs to create a VBA UserForm that allows selecting multiple images, displaying them with caption text boxes, and inserting both into a Word document upon submission.

- Product
- Microsoft Word
- Device & OS
- not provided
- Scenario
- Building an advanced UserForm in Word VBA to manage batch image insertion with corresponding user-defined text captions.
- Observed behavior
- The user requires the correct methods and logic to dynamically generate controls, load images for preview, and output the data to the document.
Ensure you have the Developer tab enabled in Word and your document is saved in a Macro-Enabled format (.docm) so that your VBA code executes properly.
Use LoadPicture and Dynamically Add Controls to the UserForm
Utilize the LoadPicture command to display selected files in Image controls, and programmatically generate matching caption text boxes at runtime.
To handle an unknown number of images, your VBA script must dynamically add Image and TextBox controls to the UserForm using the Controls.Add method. The selected file paths and caption texts are temporarily stored and later looped through to insert the content into the active document.
Open the VBA Editor by pressing ALT + F11. Insert a new UserForm and add two CommandButtons: one for 'Select Images' and one for 'Submit to Document'.
Write a subroutine triggered by the 'Select Images' button to open a FileDialog. For each selected file, use Me.Controls.Add("Forms.Image.1") to create an Image control and Me.Controls.Add("Forms.TextBox.1") for the caption.
Apply the LoadPicture(filePath) command to the Picture property of the newly created Image controls. Set the PictureSizeMode property to fmPictureSizeModeZoom to ensure the preview fits within the control's dimensions.
In the 'Submit' button's Click event, loop through your generated controls to read the file paths and caption texts. Use Selection.InlineShapes.AddPicture to insert each image into the Word document, followed by inserting the corresponding text as a caption.

Looking for a simpler way to manage documents and images? Try WPS Office.
If dealing with complex VBA macros and dynamic UserForms in Microsoft Word is becoming cumbersome, consider WPS Office. It provides an intuitive interface for batch image insertion and formatting, fully compatible with Microsoft Word documents, without the steep learning curve of advanced VBA programming.
- 1. Download and Install: Get WPS Office Free from the official website and install it on your device.
- 2. Open Your Document: Launch WPS Writer and open your existing Word document.
- 3. Insert Multiple Pictures: Go to the Insert tab, select Picture, and easily batch-insert multiple images and apply standard captions using the built-in reference tools without needing custom macros.

Frequently Asked Questions
Why does LoadPicture throw a Type Mismatch error?
This usually happens if you attempt to load an unsupported image format. Standard VBA UserForm Image controls work best with JPG, BMP, or GIF files. Ensure your dynamic file paths point to compatible formats.
How can I automatically add a caption to an image inserted via VBA?
After inserting the picture using InlineShapes.AddPicture, you can use the InsertCaption method on the resulting object, or simply programmatically insert text in the paragraph immediately following the image.
Can I resize the images dynamically when they load into the UserForm?
Yes, you can set the PictureSizeMode property of your Image control to fmPictureSizeModeZoom. This ensures the image scales proportionally to fit the control dimensions without distorting.
How do I loop through controls dynamically created on a UserForm?
You can iterate through the Me.Controls collection. To identify your dynamically created image or textbox controls, check their Name property or use the TypeName(Control) function during the loop.




