Extract Formatted Text Blocks into a Word Summary with VBA
Question details
The user needs a method to collect multiple selected text areas from a document and compile them into a summary section using VBA.

- Product
- Word
- Device & OS
- not provided
- Scenario
- Compiling specific, widely separated portions of text into an executive summary or overview section without losing their complex formatting.
- Observed behavior
- The word processor lacks a built-in direct command to automatically collect marked text blocks into a summary while preserving critical formatting like paragraphs and multilevel lists.
Before writing your scripts, ensure the Developer tab is enabled in your ribbon settings. Verify that your document contains the specific multilevel lists and formatted text you intend to summarize so you can test the macro's output accurately.
Create VBA Macros Using Bookmarks and FormattedText
This method uses a set of small VBA macros to mark selections with unique bookmarks, compile their formatted text into a summary, and clean up the bookmarks afterward.
Using the FormattedText property in VBA is highly recommended because it preserves complex formatting, such as multilevel lists and paragraph styles, much better than standard string copying.
Press Alt + F11 to launch the Visual Basic for Applications (VBA) editor. Go to Insert > Module to create a new workspace for your code.
Create a macro that assigns a uniquely named bookmark (e.g., sequentially numbered like 'Summary_1', 'Summary_2') to the currently selected text.
Draft a second macro that loops through all bookmarks matching your unique naming pattern. Use the code 'DestinationRange.FormattedText = SourceBookmark.Range.FormattedText' to insert each bookmark's exact formatting into the designated summary area.
Add a final script to delete the temporary bookmarks once the summary generation is complete. This keeps your document clean and prevents errors if you need to run the compilation again.

Utilize Mapped Content Controls
Mapped content controls provide an alternative to VBA by allowing text entered in one part of the document to automatically duplicate in another part.
Automate Document Summaries with WPS Writer
WPS Writer offers an intuitive Developer environment and robust macro support, allowing you to easily build VBA scripts to extract formatted text blocks and compile them into comprehensive summaries with exact layout preservation.
- 1. Enable Developer Tools: Open WPS Writer, go to 'Menu' > 'Options' > 'Customize Ribbon', and check the box for the 'Developer' tab to reveal macro settings.
- 2. Open the Macro Editor: Click 'Developer' on the main ribbon, then click 'Macro' or press Alt + F11 to launch the built-in WPS VBA editor.
- 3. Insert Your VBA Script: Create a new Module and paste your bookmarking and FormattedText compilation macros directly into the editor.
- 4. Run the Summary Macro: Select your text blocks, assign the bookmarks via your macro, and run the compilation script to instantly generate your formatted summary.

Frequently Asked Questions
Why does regular VBA text extraction lose my multilevel list formatting?
Standard VBA string extraction (like Range.Text) only copies the plain text values. To retain complex formatting like multilevel lists, indentations, or bolding, you must explicitly use the Range.FormattedText property in your macro script.
Can I use third-party add-ins to extract text instead of writing VBA code?
Yes, there are several free tools and templates created by Word MVPs that automate text extraction. However, these require downloading third-party software, which may require security review and additional setup before they can be safely used in a corporate environment.
Are VBA bookmarks visible in the final printed document?
No, bookmarks do not print. By default, they are hidden on the screen as well. You can make them visible for editing purposes in the document settings by checking 'Show bookmarks', which displays them as gray brackets. Running a cleanup macro ensures they are permanently removed.
Will VBA macros written for Word work in WPS Writer?
WPS Writer features high compatibility with standard Microsoft Word VBA scripts. Most macros utilizing standard objects like Bookmarks, Ranges, and FormattedText will run seamlessly in WPS Office, allowing for straightforward migration of your automated workflows.




