How to Highlight Text in Word Document using VBA?

How to Highlight Text in Word Document using VBA?


In a document use the highlighter to highlight particular text or range to make good resemblance.

With the help of little code we can achieve this task. In given example we will be using “Selection” object, developer can change this object to anything which refers to a range like grab an object by Find and take the range and perform highlight operation;

The following is the document on which we will perform highlight operation:

Code example

Sub HighlightText()
    Dim rng As Range
    Set rng = Selection.Range
    rng.HighlightColorIndex = wdBlue
End Sub

wdBlue is a constraint which can be replaced with desired color constraint provided by Micorosoft. Post execution of above code the result would look like as follow:

Next >> Word Story Ranges with code example

Leave a Reply

Your email address will not be published. Required fields are marked *