Extract Highlighted Text from Word Documents with VBA
Question details
The user needs to extract only the highlighted text from hundreds of Word documents by deleting all unhighlighted content in bulk using macros.

- Product
- Word
- Device & OS
- not provided
- Scenario
- Bulk processing hundreds of documents to isolate highlighted key terms or sections.
- Observed behavior
- Current macros find highlighted text but fail to cleanly remove unhighlighted text or struggle to apply this extraction process across hundreds of files simultaneously without merging words.
Before running batch macros or executing bulk Find and Replace operations, ensure you have backed up all your original Word documents in a separate folder to prevent accidental data loss during the automated extraction process.
Use Find and Replace to Isolate Highlighted Text
A clever formatting trick using font colors to delete unhighlighted text while preserving the highlighted words, avoiding complex VBA string manipulation.
This method avoids writing complex code to identify unhighlighted text. By making all text invisible (white) and then restoring the color of only the highlighted text, you can easily delete the invisible text in a subsequent step.
Press Ctrl+A to select all text in the document. Change the font color to White.
Press Ctrl+H to open Find and Replace. Click 'More' > 'Format' > 'Highlight' for the 'Find what' field. In the 'Replace with' field, set the font color to Automatic (or Black).
Still in the 'Replace with' field, type '^& ' (without quotes, note the space) to keep the found text and add a space after it. Click 'Replace All'. This prevents extracted words from merging together.
Open Find and Replace again. Set 'Find what' to font color White and remove the Highlight formatting. Leave 'Replace with' completely empty. Click 'Replace All' to delete the remaining white text.

Apply a VBA Macro for Batch Processing
Automate the extraction process across hundreds of documents using a VBA batch macro.
Use WPS Writer for Advanced Document Formatting and Macros
WPS Office provides robust support for VBA macros and advanced Find and Replace formatting, making it easy to batch process documents and extract highlighted text seamlessly.
- 1. Open your document: Launch WPS Writer and open the document you wish to process.
- 2. Use Find and Replace: Go to the 'Home' tab and click 'Find and Replace' to perform formatting-based text extraction.
- 3. Access the VBA Editor: Navigate to the 'Tools' or 'Developer' tab to open the VBA Editor.
- 4. Run batch macros: Write or paste your batch extraction macro and run it to process your files in bulk.

Frequently Asked Questions
Can I extract highlighted text without deleting the rest of the document?
Yes, instead of deleting unhighlighted text, you can write a VBA macro that finds highlighted text and copies it to a new, separate document, leaving the original file completely intact.
Why does my extracted text merge into one long word?
This happens because deleting the unhighlighted text removes the spaces and punctuation between the highlighted words. To fix this, insert a delimiter (like a space or comma) after each highlighted word during the Find and Replace process.
Does WPS Office support VBA macros for Word documents?
Yes, WPS Office provides VBA support in its professional and business versions, allowing you to run standard Word macros for batch processing and text extraction perfectly.




