How to Use a Word Macro to Save Figures and Captions as Separate Files
Question details
The user needs a way to automatically extract all inline images and their associated captions from a Word document and save each pair as an independent file.

- Product
- Microsoft Word
- Device & OS
- not provided
- Scenario
- Extracting multiple figures and captions into individual files for easier management, archiving, or publishing.
- Observed behavior
- The user has a single document containing multiple figures with captions and requires an automated VBA solution to split them into separate documents.
Ensure you have the Developer tab enabled in your Word ribbon, as you will need access to the Visual Basic Editor to insert and run the macro script.
Use a VBA Macro to Extract Figures and Captions
Create and run a VBA macro that searches for the Caption style, identifies the related inline image, and saves them together in a new document.
This solution uses a custom VBA script to automate the extraction process. The macro looks for paragraphs formatted with the 'Caption' style, locates the preceding inline shape (the figure), and copies both into a new document.
The new documents are saved in an automatically generated subfolder within the same directory as your original file, named according to the figure's label (e.g., Fig1.docx).
Press 'Alt + F11' in Microsoft Word to open the Visual Basic for Applications (VBA) editor.
In the Project Explorer pane on the left, right-click your document's name, select 'Insert', and choose 'Module'.
Paste your VBA code designed to search for the 'Caption' style and copy the preceding inline shape into the empty module window.
Close the VBA editor or press 'F5' while inside the module to run the macro. The script will create a subfolder and generate the separate Word files for each figure.

Try WPS Office for Your Document Processing Needs
While running complex VBA macros often requires specific Microsoft Word configurations, WPS Office provides a lightweight, highly compatible alternative for handling complex document layouts, image insertions, and daily word processing tasks without the heavy subscription fees.

Frequently Asked Questions
Why is my VBA macro not finding the figures in my document?
The macro relies on specific formatting to locate figures. Ensure your images are inserted as 'In Line with Text' rather than floating, and that the text below them is strictly formatted using Word's built-in 'Caption' style.
Can I save the extracted figures as image files instead of Word documents?
Yes, but it requires a modified VBA script. The macro provided in this solution creates separate .docx files containing both the image and the text. To export as standalone image files (like PNG or JPEG), you would need to use the 'SaveAsPicture' method in VBA.
Where does the macro save the new separate figure files?
The macro creates a new subfolder in the exact same directory where your original source document is saved. It names the individual files based on the text appearing before the colon in the caption, such as 'Fig1.docx'.
How do I correctly apply the 'Caption' style to my text?
Select the text below your image, navigate to the 'Home' tab, and click on 'Caption' in the Styles pane. Alternatively, right-click the image and select 'Insert Caption' to automatically generate properly formatted caption text.




