Microsoft Office Forums Find and highlight text in MS Word document containing word

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 04-08-2018, 08:48 PM
Jovan Yong Jovan Yong is offline Find and highlight text in MS Word document containing word Windows 10 Find and highlight text in MS Word document containing word Office 2016
Novice
Find and highlight text in MS Word document containing word
 
Join Date: Apr 2018
Posts: 5
Jovan Yong is on a distinguished road
Default 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?
Reply With Quote
  #2  
Old 04-08-2018, 09:04 PM
Guessed's Avatar
Guessed Guessed is offline Find and highlight text in MS Word document containing word Windows 10 Find and highlight text in MS Word document containing word Office 2016
Expert
 
Join Date: Mar 2010
Location: Canberra/Melbourne Australia
Posts: 1,374
Guessed is a jewel in the roughGuessed is a jewel in the roughGuessed is a jewel in the roughGuessed is a jewel in the rough
Default

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
Reply With Quote
  #3  
Old 04-08-2018, 10:08 PM
Jovan Yong Jovan Yong is offline Find and highlight text in MS Word document containing word Windows 10 Find and highlight text in MS Word document containing word Office 2016
Novice
Find and highlight text in MS Word document containing word
 
Join Date: Apr 2018
Posts: 5
Jovan Yong is on a distinguished road
Default

Quote:
Originally Posted by Guessed View Post
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?
I want to highlight all the PQC with numbers, as for the ip numbers, i do not need to highlight it.
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
Reply With Quote
  #4  
Old 04-08-2018, 11:46 PM
Guessed's Avatar
Guessed Guessed is offline Find and highlight text in MS Word document containing word Windows 10 Find and highlight text in MS Word document containing word Office 2016
Expert
 
Join Date: Mar 2010
Location: Canberra/Melbourne Australia
Posts: 1,374
Guessed is a jewel in the roughGuessed is a jewel in the roughGuessed is a jewel in the roughGuessed is a jewel in the rough
Default

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
Refer to the attached graphic to see what the search and replace dialog would look like. Note: I decided to remove the replacewith text and also check the Whole Word setting after capturing the screen shot but the result is essentially the same.
Attached Images
File Type: png Capture.PNG (14.3 KB, 11 views)
__________________
Andrew Lockton
Chrysalis Design, Melbourne Australia
Reply With Quote
  #5  
Old 04-09-2018, 12:02 AM
Jovan Yong Jovan Yong is offline Find and highlight text in MS Word document containing word Windows 10 Find and highlight text in MS Word document containing word Office 2016
Novice
Find and highlight text in MS Word document containing word
 
Join Date: Apr 2018
Posts: 5
Jovan Yong is on a distinguished road
Default

Quote:
Originally Posted by Guessed View Post
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
Refer to the attached graphic to see what the search and replace dialog would look like. Note: I decided to remove the replacewith text and also check the Whole Word setting after capturing the screen shot but the result is essentially the same.
Hmm, how about if i just want to select PQC , everything related to it is selected?
Because the number after PQC is randomize
Reply With Quote
  #6  
Old 04-09-2018, 02:59 AM
macropod's Avatar
macropod macropod is offline Find and highlight text in MS Word document containing word Windows 7 64bit Find and highlight text in MS Word document containing word Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 19,642
macropod is a splendid one to beholdmacropod is a splendid one to beholdmacropod is a splendid one to beholdmacropod is a splendid one to beholdmacropod is a splendid one to beholdmacropod is a splendid one to beholdmacropod is a splendid one to beholdmacropod is a splendid one to behold
Default

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
[MS MVP - Word]
Reply With Quote
Reply

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 qkjack Word VBA 7 02-21-2018 07:09 PM
Find and highlight text in MS Word document containing word Find and highlight multiple words in MS Word document AtaLoss Word VBA 33 10-10-2017 01:35 AM
Find and highlight text in MS Word document containing word 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


All times are GMT -7. The time now is 12:22 PM.


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