Microsoft Office Forums

Go Back   Microsoft Office Forums > >

 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
  #3  
Old 06-27-2013, 07:37 AM
big0 big0 is offline Macro to highlight words Windows 7 64bit Macro to highlight words Office 2010 64bit
Novice
 
Join Date: Jun 2013
Posts: 10
big0 is on a distinguished road
Default

I also found this code on the Web.

I also have a macro for highlighting lists of Words which could be adapted
to your own requirements. Replace the words in the vFindText arrays with
your own words. You can continue the theme with other colours and words as
required.


Sub ReplaceList()
Dim vFindText As Variant
Dim vReplText As Variant
Dim i As Long

'highlight red words
Options.DefaultHighlightColorIndex = wdRed
Selection.Find.ClearFormatting
Selection.Find.Replacement.ClearFormatting

vFindText = Array("anger", "violence", "fighting")
vReplText = "^&"
With Selection.Find
.Forward = True
.Wrap = wdFindContinue
.MatchWholeWord = True
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
.Format = True
.MatchCase = False

For i = LBound(vFindText) To UBound(vFindText)
.Text = vFindText(i)
.Replacement.Text = vReplText
.Replacement.Highlight = True
.Execute replace:=wdReplaceAll
Next i
End With

'Highlight blue words
Options.DefaultHighlightColorIndex = wdBlue

vFindText = Array("depression", "misery")
vReplText = "^&"
With Selection.Find
.Forward = True
.Wrap = wdFindContinue

For i = LBound(vFindText) To UBound(vFindText)
.Text = vFindText(i)
.Replacement.Text = vReplText
.Replacement.Highlight = True
.Execute replace:=wdReplaceAll
Next i
End With
End Sub
Reply With Quote
 



Similar Threads
Thread Thread Starter Forum Replies Last Post
Macro to highlight words Find and highlight multiple words in MS Word document AtaLoss Word VBA 37 09-22-2021 12:04 PM
Macro to highlight words Macro to highlight a list of words bakerkr Word VBA 4 10-19-2017 02:23 PM
Macro to highlight words How to make it highlight blocks of text (words) without highlighting extra space @end seortm Word 3 03-30-2015 08:12 AM
Macro to highlight words Highlight and then replace multiple words redhin Word VBA 5 03-05-2013 05:42 AM
Macro to highlight words Find and highlight all words ending in -ly RBLampert Word VBA 13 10-23-2012 04:45 PM

Other Forums: Access Forums

All times are GMT -7. The time now is 01:00 PM.


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