#1
|
|||
|
|||
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, |
#2
|
||||
|
||||
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 |
#3
|
|||
|
|||
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. |
#4
|
||||
|
||||
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 |
Tags |
highlighting, multiple, words |
Thread Tools | |
Display Modes | |
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
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 |
VBA to highlight words if used too much | aolszewski | Word VBA | 3 | 11-23-2013 02:07 AM |
Highlight all underlined words | zdodson | Word VBA | 1 | 07-11-2013 04:53 PM |
Macro to highlight words | bertietheblue | Word VBA | 9 | 07-01-2013 12:39 PM |