VBA & Macro Problems

Hide Non-Highlighted Text in Word with a VBA Macro

Phi Hung VoPhi Hung Vo Nov 22, 2026 868 views

Question details

Use a Word VBA macro to hide text that has no highlight while keeping highlighted text visible.

Hide Non-Highlighted Text in Word with a VBA Macro
Product
Microsoft Word
Device & OS
not provided
Scenario
The user wants to focus on highlighted passages in a document without deleting the remaining text.
Observed behavior
Non-highlighted text should have the Hidden font attribute applied, while highlighted text remains visible.
Before you start

Apply highlights using Word’s Home > Text Highlight Color tool; font color and paragraph shading are not the same as highlighting. The macro below processes the main document body, not headers, footers, or text boxes.

Solution 1Recommended

Run a Word VBA macro to hide non-highlighted text

Use this macro to apply Hidden formatting to non-highlighted characters in the main document body and make highlighted characters visible.

1
Save as a macro-enabled document

In Word, select File > Save As and choose Word Macro-Enabled Document (*.docm) if you want to store the macro in the document.

2
Open the VBA editor

On Windows, press Alt+F11. In the VBA editor, select the document’s project, then choose Insert > Module.

3
Add the macro

Paste this code into the module: Sub HideNonHighlightedText() Dim charRange As Range For Each charRange In ActiveDocument.Content.Characters If charRange.HighlightColorIndex = wdNoHighlight Then charRange.Font.Hidden = True Else charRange.Font.Hidden = False End If Next charRange End Sub

4
Run the macro

Return to Word, press Alt+F8 on Windows, select HideNonHighlightedText, and click Run. Enable macros only if you trust the document and its source.

5
Hide hidden-text marks

Go to File > Options > Display and clear Hidden text and Show all formatting marks. Non-highlighted text remains in the document but should no longer appear on screen.

Run a Word VBA macro to hide non-highlighted text
Processing and visibility: The macro checks characters individually, so it may take time in a long document. It also removes Hidden formatting from highlighted characters in the main body.
Free Microsoft Office alternative

Work with Word documents in WPS Writer

WPS Office is a free, lightweight alternative with a familiar interface for opening and editing Word documents. It supports common Word formats for an easier move between applications, but it does not fix or replace the Word VBA macro described above.

Open and edit Microsoft Word DOC and DOCX files.Use highlighting tools to mark important passages in WPS Writer.Navigate documents with a familiar Office-style interface.Use a free, lightweight office suite.
microsoft office alternative - wps office

Frequently Asked Questions

How can I see the hidden text again in Word?

Go to File > Options > Display and select Hidden text. To remove Hidden formatting permanently, select the text, open the Font dialog, and clear Hidden.

Does the macro recognize colored text or paragraph shading?

No. It checks Word’s text highlight attribute. Use Home > Text Highlight Color to mark the passages you want to keep visible.

Will the macro hide text in headers and footers?

No. The supplied macro processes ActiveDocument.Content, which covers the main document body. Headers, footers, and text boxes require additional code.

Why can I still see the non-highlighted text after running the macro?

In File > Options > Display, clear both Hidden text and Show all formatting marks. Hidden text can still be displayed when those options are enabled.

Why should I save the document as a DOCM file?

A Word Macro-Enabled Document (*.docm) can store the macro in the document. Choose File > Save As and select that format if you want the macro to remain available in the file.