When working with Microsoft 365 and Office , automating highlights is a massive time-saver. The core solution relies on Visual Basic for Applications (VBA). This specific macro to highlight sentences that contain one or more words will read a list of target words from a separate document and apply a bright green highlight to any complete sentence in your active document containing those words
The Core Solution for a Macro to Highlight Sentences That Contain One or More Words
Before changing anything else, begin with the interface and account named in this action: Prepare your keywords file. Create a new Word document named HighlightWordsFromFile.docx and save it to your Mac Desktop. Type one keyword per line (e.g., consectetur, incididunt) and save
Step-by-Step Guide: Running the Macro to Highlight Sentences That Contain One or More Words
Follow these Word actions for Use a Macro to Highlight Sentences That Contain Specific Words in order. The key interface checkpoint is Developer Tab -> Visual Basic Editor -> Insert Menu.

- Prepare your keywords file. Create a new Word document named HighlightWordsFromFile.docx and save it to your Mac Desktop. Type one keyword per line (e.g., consectetur, incididunt) and save
- Enable the Developer Tab. Go to Word > Preferences > Ribbon & Toolbar, check the "Developer" box, and apply
- Open the VBA Editor. Navigate to the Developer tab on the ribbon and click the "Visual Basic" button
- Insert a Module. In the VBA editor menu, click Insert > Module to open a blank script window
- Paste the exact code. Copy and paste the following tested script into the module window
- Update the file path. Change YourUsername in the filePath code string to your actual MacOS username
- Run the Macro. Close the VBA editor, return to your main text document, click "Macros" on the Developer tab, select HighlightSentencesFromFile , and click "Run". Verify that target sentences are highlighted green
Sub Demo()
Application.ScreenUpdating = False
Dim i As Long, j As Long, StrIn As String, StrOut As String
StrIn = InputBox("What is the Text to Find")
For i = 0 To UBound(Split(StrIn, ","))
j = 0
With ActiveDocument.Range
With .Find
.ClearFormatting
.Text = Trim(Split(StrIn, ",")(i))
.Forward = True
.Wrap = wdFindStop
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Do While .Find.Execute
j = j + 1
.Sentences.First.HighlightColorIndex = wdBrightGreen
.Collapse wdCollapseEnd
Loop
StrOut = StrOut & vbCr & Trim(Split(StrIn, ",")(i)) & ":" & vbTab & j
End With
Next
Application.ScreenUpdating = True
MsgBox "The following instances were found." & StrOut
End SubAlternative Method to the Macro to Highlight Sentences That Contain One or More Words
- Action: Press Cmd + Shift + H on MacOS to open Find and Replace.
- Execution: Search for your specific word, click "Find All", and apply the highlight button from the Home tab.
- Verdict: Omit this manual method as a true replacement. Advanced Find only highlights the specific words themselves, not the entire sentence context. The macro remains the only genuinely effective solution for this exact formatting need.
How to Verify the Word Result
Validate the change before closing the app: Run the Macro. Close the VBA editor, return to your main text document, click "Macros" on the Developer tab, select HighlightSentencesFromFile , and click "Run". Verify that target sentences are highlighted green A different result usually means the wrong file, account, or Module was used.
WPS Office: A Free Microsoft Office Alternative for Use a Macro to Highlight Sentences That Contain
For local work related to Use a Macro to Highlight Sentences That Contain Specific Words, WPS Office is a free Microsoft Office-compatible alternative. It does not reproduce every proprietary Word service or administrator control, so use the Microsoft steps above when the task depends on that specific platform.
While you complete “Use a Macro to Highlight Sentences That Contain Specific Words” in Microsoft’s interface, use WPS Writer for DOCX and RTF files, styles, comments, track changes, and PDF export; WPS AI can also draft, rewrite, summarize, or translate document text. Because the desktop interface follows familiar document, spreadsheet, presentation, and PDF conventions, most users can move common local work without rebuilding their workflow.

Word FAQs About Use a Macro to Highlight Sentences That Contain Specific Words
How do I enable the Developer tab on MacOS to run this code?
Open Microsoft Word, click on "Word" in the top Apple menu bar, and select "Preferences". Go to "Ribbon & Toolbar" and scroll down the "Main Tabs" list on the right. Check the box next to "Developer" and click "Save" to make the tab visible.
Why is my macro running slowly on large documents?
Looping through every single sentence in a massive document consumes significant memory. To speed up the macro process, add Application.ScreenUpdating = False directly after the Sub HighlightSentencesFromFile() line, and Application.ScreenUpdating = True right before End Sub to prevent the screen from visually refreshing during execution.
Can I change the highlight color from bright green in the VBA code?
Yes. In the script, locate the exact line sentence.HighlightColorIndex = wdBrightGreen . You can change wdBrightGreen to other Word VBA color constants like wdYellow , wdPink , or wdTurquoise depending on your visual preference.
Will this code work if my desktop keyword list has blank lines?
Blank lines in your keyword document might cause the macro to behave unexpectedly, potentially highlighting every sentence because it searches for an empty string. Ensure your HighlightWordsFromFile.docx has absolutely no empty lines, or manually remove them before running the script.




