VBA Macro to Highlight Capital Letters Inside Sentences in Word
Question details
The user needs a VBA macro for Word that scans a document and highlights any capital letters located in the middle of sentences, intentionally excluding the first capitalized letter of each sentence.

- Product
- Word
- Device & OS
- not provided
- Scenario
- Proofreading or formatting a document where internal capitalization needs to be audited, stylized, or corrected automatically.
- Observed behavior
- Currently, manual inspection is required to find mid-sentence capital letters. The goal is to automate this process using VBA, successfully skipping the normal sentence-starting capitals.
Ensure that your document is saved and that you have enabled macros in your word processor's Trust Center settings before running custom VBA code.
Use the Sentence Range Comparison Macro
This is the recommended method. It uses Word's built-in Sentences collection to check if a found capital letter is at the very beginning of the sentence, highlighting it in red if it is not.
This macro searches for any uppercase letter from A to Z using wildcards. When it finds one, it verifies the position of the character against the start position of the current sentence.
Open your document and press Alt + F11 to launch the Microsoft Visual Basic for Applications (VBA) editor.
In the top menu, click 'Insert' and then select 'Module' to create a blank workspace for your code.
Copy and paste the following code into the module window: Sub HighlightCaps() Dim rng As Range Dim sent As Range Set rng = ActiveDocument.Range With rng.Find .ClearFormatting .Text = "[A-Z]" .MatchWildcards = True .Forward = True .Wrap = wdFindStop Do While .Execute Set sent = rng.Sentences(1) If rng.Start <> sent.Start Then rng.HighlightColorIndex = wdRed End If DoEvents Loop End With End Sub
Close the VBA editor. Back in your document, press Alt + F8, select 'HighlightCaps' from the macro list, and click 'Run'. All mid-sentence capital letters will now be highlighted in red.

Use the Word-Level Character Check Macro
An alternative approach that scans through individual words of two or more letters, checking each character after the first one for capitalization.
Use VBA Macros Efficiently with WPS Office
WPS Office offers robust VBA support in its advanced versions, allowing you to seamlessly run custom macros to automate complex tasks like highlighting mid-sentence capital letters.
- 1. Open WPS Writer: Launch WPS Writer and open your target document.
- 2. Access Macro Tools: Navigate to the 'Tools' tab on the ribbon and click on 'Macros'.
- 3. Open VBA Editor: Select 'Visual Basic Editor', insert a new module, and paste your macro code.
- 4. Execute: Run the macro directly from the editor or the Macros list to instantly highlight your text.

Frequently Asked Questions
Why is the macro highlighting letters right after an abbreviation?
The macro relies on Word's built-in Sentences collection. Word often interprets the period after an abbreviation (like 'Mr.' or 'Dr.') as the end of a sentence. Therefore, the next word is treated as the start of a new sentence. You may need to manually adjust these edge cases.
How do I remove the red highlights after I am done reviewing?
To remove the highlights, select the entire document (Ctrl + A), go to the Home tab, click the arrow next to the 'Text Highlight Color' icon, and choose 'No Color'.
Does this macro work on words that are in ALL CAPS?
Yes. If a sentence has a word in ALL CAPS, the macro will evaluate each letter. Since they are uppercase and not the first character of the sentence, all letters in that word will be highlighted.
Why isn't the macro running on my computer?
If the macro doesn't run, your Trust Center settings might be blocking it. Go to File > Options > Trust Center > Trust Center Settings > Macro Settings, and select 'Enable all macros' (use with caution and only for trusted documents).




