Microsoft Office Forums

Go Back   Microsoft Office Forums > >

 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
  #2  
Old 09-29-2019, 12:27 AM
gmayor's Avatar
gmayor gmayor is offline search and highlight many words in ms doc Windows 10 search and highlight many words in ms doc Office 2016
Expert
 
Join Date: Aug 2014
Posts: 4,144
gmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud of
Default

How many words? One approach is to use a pair of arrays to hold the words and the colours associated with those words. e.g.

Code:
Sub Macro1()
'Graham Mayor - https://www.gmayor.com - Last updated - 29 Sep 2019 
Dim vFindText As Variant
Dim vColor As Variant
Dim i As Long
    vFindText = Array("Lorem", "ipsum", "amet") 'The word list
    vColor = Array(wdYellow, wdTurquoise, wdBrightGreen) 'The same number of items in this list as in the word list
    For i = 0 To UBound(vFindText)
        Options.DefaultHighlightColorIndex = vColor(i)
        With Selection
            .HomeKey wdStory
            With .Find
                .ClearFormatting
                .Replacement.ClearFormatting
                .Text = vFindText(i)
                .Replacement.Text = "^&"
                .Replacement.Highlight = True
                .Forward = True
                .Wrap = wdFindContinue
                .Format = True
                .MatchCase = False
                .MatchWholeWord = False
                .MatchKashida = False
                .MatchDiacritics = False
                .MatchAlefHamza = False
                .MatchControl = False
                .MatchWildcards = False
                .MatchSoundsLike = False
                .MatchAllWordForms = False
                .Execute Replace:=wdReplaceAll
            End With
        End With
    Next i
End Sub
__________________
Graham Mayor - MS MVP (Word) (2002-2019)
Visit my web site for more programming tips and ready made processes www.gmayor.com
Reply With Quote
 

Tags
highlighting, multiple, words



Similar Threads
Thread Thread Starter Forum Replies Last Post
search and highlight many words in ms doc Highlight words from a list Nanaia Word VBA 3 09-07-2018 02:13 PM
How to find (highlight) two and more words in a list of 75k single words in Word 2010 Usora Word 8 05-29-2018 03:34 AM
search and highlight many words in ms doc VBA to highlight words if used too much aolszewski Word VBA 3 11-23-2013 02:07 AM
search and highlight many words in ms doc Highlight all underlined words zdodson Word VBA 1 07-11-2013 04:53 PM
search and highlight many words in ms doc Macro to highlight words bertietheblue Word VBA 9 07-01-2013 12:39 PM

Other Forums: Access Forums

All times are GMT -7. The time now is 07:47 AM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2025, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2025 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft