#1
|
|||
|
|||
Find and highlight text in MS Word document containing word
Hi guys,
Need some help here. I would like to highlight text that contains the word that i want to search. For example PQC701 10.143.20.209 PQC702 10.143.20.225 PQC703 10.143.20.241 PQC704 10.143.21.1 PQC705 10.143.21.17 I wanted to highlight whole of PQC 701-705 in yellow using macro. Would it be possible? |
#2
|
||||
|
||||
What other examples do you have that you don't want to highlight? For example do they always increment or might there be content between 701 and 705 which shouldn't be highlighted?
Do you want to highlight the PQC lines only or also the following ip numbers? If there is a 701, must there always be a 705? What happens if there isn't?
__________________
Andrew Lockton Chrysalis Design, Melbourne Australia |
#3
|
|||
|
|||
Quote:
For example if i search "PQC" Below containing the word PQC must be highlighted. PQC701 10.143.20.209 PQC702 10.143.20.225 PQC703 10.143.20.241 PQC704 10.143.21.1 PQC705 10.143.21.17 |
#4
|
||||
|
||||
You can do that with a single search and replace. If it needs to be a macro, recording that and doing a quick tidy gives you this macro.
Code:
Sub Macro2() Options.DefaultHighlightColorIndex = wdBrightGreen With Selection.Find .ClearFormatting .Replacement.ClearFormatting .Replacement.Highlight = True .Text = "PQC70([1-5])" .Replacement.Text = "" .Forward = True .Wrap = wdFindContinue .Format = True .MatchCase = False .MatchWholeWord = True .MatchAllWordForms = False .MatchSoundsLike = False .MatchWildcards = True .Execute Replace:=wdReplaceAll End With End Sub
__________________
Andrew Lockton Chrysalis Design, Melbourne Australia |
#5
|
|||
|
|||
Quote:
Because the number after PQC is randomize |
#6
|
||||
|
||||
If what follows PQC is always a 3-digit number, you can use an ordinary Find/Replace, where:
Find = PQC^#^#^# Replace = ^& and you set the replacement highlight colour to whatever you want. No macros required.
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
Tags |
highlighted-text, macro, vba code |
Thread Tools | |
Display Modes | |
|
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 |
Find and highlight multiple words in MS Word document | qkjack | Word VBA | 7 | 02-21-2018 07:09 PM |
How to highlight text in a Word document using a word list from another document | Gilvv | Word VBA | 9 | 11-01-2016 04:44 PM |
Can Word highlight the same text in the Reviewing Pane as in the main document? | wordistheword | Word | 4 | 09-09-2013 04:50 AM |
find - reading highlight - highlight all / highlight doesn't stick when saved | bobk544 | Word | 3 | 04-15-2009 03:31 PM |