Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 09-28-2019, 10:57 PM
sk1949 sk1949 is offline search and highlight many words in ms doc Windows 10 search and highlight many words in ms doc Office 2019
Novice
search and highlight many words in ms doc
 
Join Date: Aug 2019
Posts: 2
sk1949 is on a distinguished road
Default search and highlight many words in ms doc

Friends: I need help with a macro that will search many separate words in a doc and highlight them all at end of search. Color of highlighting could be an option,too. Variations in tense/ forms would be added feature. Regards,
Reply With Quote
  #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,101
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 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
  #3  
Old 09-30-2019, 09:11 PM
sk1949 sk1949 is offline search and highlight many words in ms doc Windows 10 search and highlight many words in ms doc Office 2019
Novice
search and highlight many words in ms doc
 
Join Date: Aug 2019
Posts: 2
sk1949 is on a distinguished road
Default

Sir, Thank you. My problem is this: I wish to find & highlight ALL of the words ( say around 10 words) in ONE GO. Color of highlight is not an issue, though it helps. If variants are possible ( like eat=eats,eating, eaten; eat treated as part word) it'll be additional help. If wildcard is a possibility then even better. I intend using this macro to locate most number of such words available in a word doc. Macro should PROMPT for keying in words to be searched as an array. Words searched will be different every time the Macro is used. EOF can be, say, ENTER. I am using WIN10. Highlight to stay till doc is closed. Input shall be case INsensitive. Please give me a working and complete macro which can directly be used. Though I can understand I have not tried writing programs myself.
regards.
Reply With Quote
  #4  
Old 10-01-2019, 01:29 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,101
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 of
Default

You cannot highlight them all i one pass. The best that you can do is what I have suggested. You can set whatever options you want in the code, just as you would with the Replace function
__________________
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
Reply

Tags
highlighting, multiple, words

Thread Tools
Display Modes


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 12:07 PM.


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