Microsoft Office Forums

Go Back   Microsoft Office Forums > >

 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
  #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: 3,997
Guessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant future
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, 29 views)
__________________
Andrew Lockton
Chrysalis Design, Melbourne Australia
Reply With Quote
 

Tags
highlighted-text, macro, vba code



Similar Threads
Thread Thread Starter Forum Replies Last Post
Find and highlight text in MS Word document containing word 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
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

Other Forums: Access Forums

All times are GMT -7. The time now is 08:40 AM.


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