VBA & Macro Problems

Extract Highlighted Text from Word Documents with VBA

John WilsonJohn Wilson Oct 28, 2026 869 views

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.

Extract Highlighted Text from Word Documents using VBA
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 you start

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.

Solution 1Recommended

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.

1
Change all text to white

Press Ctrl+A to select all text in the document. Change the font color to White.

2
Restore highlighted text color

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).

3
Insert delimiters to separate words

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.

4
Delete unhighlighted text

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.

Use Find and Replace to Isolate Highlighted Text
Macro Automation: You can record these exact Find and Replace steps into a VBA macro to apply them to other documents instantly.
Efficient Document Processing

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. 1. Open your document: Launch WPS Writer and open the document you wish to process.
  2. 2. Use Find and Replace: Go to the 'Home' tab and click 'Find and Replace' to perform formatting-based text extraction.
  3. 3. Access the VBA Editor: Navigate to the 'Tools' or 'Developer' tab to open the VBA Editor.
  4. 4. Run batch macros: Write or paste your batch extraction macro and run it to process your files in bulk.
Fully compatible with Microsoft Word (.docx) formats.Built-in VBA editor for creating and running batch processing macros.Advanced Find and Replace features for complex formatting tasks.Lightweight and fast performance when handling hundreds of files.
QA img-9

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.