logo
search
VBA & Macro Problems

VBA Macro to Highlight Capital Letters Inside Sentences in Word

Camila MilosovichCamila Milosovich Oct 10, 2026 869 views

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.

How to Highlight Capital Letters Inside Sentences Using a VBA Macro in Word
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.
Before you start

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.

Solution 1Recommended

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.

1
Open the VBA Editor

Open your document and press Alt + F11 to launch the Microsoft Visual Basic for Applications (VBA) editor.

2
Insert a New Module

In the top menu, click 'Insert' and then select 'Module' to create a blank workspace for your code.

3
Paste the VBA 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

4
Run the Macro

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 Sentence Range Comparison Macro
Highlight Color Customization: If you prefer a different highlight color, you can change 'wdRed' in the code to 'wdYellow', 'wdGreen', or another standard Word color constant.
Advanced VBA Support in WPS Office

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. 1. Open WPS Writer: Launch WPS Writer and open your target document.
  2. 2. Access Macro Tools: Navigate to the 'Tools' tab on the ribbon and click on 'Macros'.
  3. 3. Open VBA Editor: Select 'Visual Basic Editor', insert a new module, and paste your macro code.
  4. 4. Execute: Run the macro directly from the editor or the Macros list to instantly highlight your text.
Fully compatible with Microsoft Word (.doc, .docx, .docm) formatsSupports standard VBA syntax and macro executionLightweight text processor with blazing-fast performanceFree alternative offering a highly familiar user interface
QA img-9

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