#1
|
|||
|
|||
Macro to highlight a list of words
I came across a macro that will highlight a certain word, in the below example I used the word to.
I'd like to use a list of words, which will allow me to add or delete words as necessary. Is this possible? VBA is okay instead of a macro. Thanks Kevin Code:
Selection.Find.ClearFormatting Selection.Find.Replacement.ClearFormatting Selection.Find.Replacement.Highlight = True With Selection.Find .Text = "to" .Replacement.Text = "to" .Forward = True .Wrap = wdFindContinue .Format = True .MatchCase = False .MatchWholeWord = False .MatchWildcards = False .MatchSoundsLike = False .MatchAllWordForms = False End With Selection.Find.Execute Replace:=wdReplaceAll Options.DefaultHighlightColorIndex = wdYellow Selection.Range.HighlightColorIndex = wdYellow Last edited by macropod; 05-14-2013 at 08:25 PM. Reason: Added code tags & formatting |
#2
|
|||
|
|||
Quote:
Code:
Sub ListChange() Dim r As Range Dim MyList() As String Dim i As Long MyList = Split("dot,com,like", ",") For i = 0 To UBound(MyList()) Set r = ActiveDocument.Range With r.Find .Text = MyList(i) .Replacement.Highlight = wdYellow .Execute Replace:=wdReplaceAll End With Next End Sub Note that nothing is selected. |
#3
|
|||
|
|||
Thanks
Thanks for the help,worked great!
|
#4
|
|||
|
|||
I was looking for something like this. Can the checking of the words can be done from a database excel. I have excel sheet having hundred words and if these words are there in the word file it must be highlighted.
|
#5
|
||||
|
||||
Quote:
The use of an Excel workbook as a Find/Replace data source has been discussed numerous times. For example: https://www.msofficeforums.com/word-...html#post34254
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
Find and highlight multiple words in MS Word document | AtaLoss | Word VBA | 37 | 09-22-2021 12:04 PM |
How to make it highlight blocks of text (words) without highlighting extra space @end | seortm | Word | 3 | 03-30-2015 08:12 AM |
Highlight and then replace multiple words | redhin | Word VBA | 5 | 03-05-2013 05:42 AM |
Find and highlight all words ending in -ly | RBLampert | Word VBA | 13 | 10-23-2012 04:45 PM |
find - reading highlight - highlight all / highlight doesn't stick when saved | bobk544 | Word | 3 | 04-15-2009 03:31 PM |