Microsoft Office Forums Macro to highlight words

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 06-22-2013, 10:47 AM
bertietheblue bertietheblue is offline Macro to highlight words Windows 7 64bit Macro to highlight words Office 2003
Advanced Beginner
Macro to highlight words
 
Join Date: May 2012
Location: United Kingdom
Posts: 45
bertietheblue is on a distinguished road
Default Macro to highlight words


My job involves checking for definitions in legal documents for clients. I want to ignore certain capitalised terms that never need defining (countries, months etc). I'd like to build up a list of these terms and then at the click of button highlight them throughout a document, so I'm left only checking relevant terms. How do I do this?

This is a big thing - it's what I do about 30 hours a week - so I'd really appreciate any help (bearing in mind that I've never used macros or VBA before and have limited understanding of how they work or whether they are what is needed).

Thanks
Bertie
Reply With Quote
  #2  
Old 06-27-2013, 07:33 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

Here is some code that I use to help me:

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
Reply With Quote
  #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
  #4  
Old 06-27-2013, 10:40 AM
bertietheblue bertietheblue is offline Macro to highlight words Windows 7 64bit Macro to highlight words Office 2003
Advanced Beginner
Macro to highlight words
 
Join Date: May 2012
Location: United Kingdom
Posts: 45
bertietheblue is on a distinguished road
Default

Much appreciated, Big0. I've taken Monday off so I can have a look at this, try and make sense of how to enter it - I know nothing about codes - and give it a shot.
Reply With Quote
  #5  
Old 06-27-2013, 11:52 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

Open you document
Click ALT-F11
Go to INSERT
Click on Module
Paste Code
Save it
Close it
Should take you back to your document, if not reopen
Click VIEW
Click MACRO
Your MACRO name should come up and then click RUN

Should work

big0
Reply With Quote
  #6  
Old 06-27-2013, 12:26 PM
bertietheblue bertietheblue is offline Macro to highlight words Windows 7 64bit Macro to highlight words Office 2003
Advanced Beginner
Macro to highlight words
 
Join Date: May 2012
Location: United Kingdom
Posts: 45
bertietheblue is on a distinguished road
Default

Thanks for the instructions, Big0. Monday could be a day of celebration! I'd do it now but I'm on a work bender for the next few days.
Reply With Quote
  #7  
Old 07-01-2013, 02:42 AM
bertietheblue bertietheblue is offline Macro to highlight words Windows 7 64bit Macro to highlight words Office 2003
Advanced Beginner
Macro to highlight words
 
Join Date: May 2012
Location: United Kingdom
Posts: 45
bertietheblue is on a distinguished road
Default

Hi Big0

OK, I tried it, replacing your Array with the following line:

vFindText = Array("Schedule", "English", "The", "United States", "Scheduled Completion Date")

It replaced 'Schedule' with red but not the other words - any idea?

Anyway, this is definitely on the right tracks so I'm very grateful. I need to develop this further so that I can quickly locate standalone terms and multi-word terms, so that, eg, I can highlight:

'[not preceded by an upper-case word with certain exceptions, eg 'The'] Issuer [not followed by any upper-case word]', so that '[The/Each etc] Issuer' is highlighted but not 'Subordinated Issuer', 'Issuer Event of Default' etc.

or highlight multi-words so, eg, highlight instances of 'Subordinated Issuer' but not the 2 words separately.

And to do this for hundreds of terms in each document!

(Down the line, the elusive goal would be to auto-locate and list bold definitions in a document and auto-list terms that are not used except where defined - probably not achievable; otherwise the program would be out there, but as near as dammit would suit me)

The programming skills would, I imagine, be quite advanced to achieve what I want, but do you think this can be developed further? And if so, what's the most cost-effective way (obviously, I wouldn't expect anyone to do this for free) -I was thinking of contacting a university department. Or do you have the skills? PM me if maybe so.

Thanks
Bertie

Last edited by bertietheblue; 07-01-2013 at 05:59 AM.
Reply With Quote
  #8  
Old 07-01-2013, 02:52 AM
bertietheblue bertietheblue is offline Macro to highlight words Windows 7 64bit Macro to highlight words Office 2003
Advanced Beginner
Macro to highlight words
 
Join Date: May 2012
Location: United Kingdom
Posts: 45
bertietheblue is on a distinguished road
Default

I should say at the moment I'm jut using wildcards, specifically (eg Issuer):

"[A-Z][a-z]{3,} Issuer" [not highlight] - to see if preceded by u/c word (having already highlighted all u/c words at beginning of paras (by highlighting wildcard 13^[A-Z]) and sentences (by highlighting all instances of '. ^$' and '. ^$')

and

"Issuer [A-Z]" to see if followed by u/c word.

Time-consuming!
Reply With Quote
  #9  
Old 07-01-2013, 12:36 PM
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

Look through each of the vFindText in the code and add your word that you want highlighted. I see TWO vFindText CODES. One is Red and the other is blue, if you need additional colors. Then you can copy the start of code and the end of code and change to the next color. See below:

'highlight yellow words
Options.DefaultHighlightColorIndex = wdYellow
Selection.Find.ClearFormatting
Selection.Find.Replacement.ClearFormatting

vFindText = Array("Teacher", "Students", "Grades")
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


Then copy and paste additional colors into the code below: Make sure you change

From this:
'highlight yellow words
Options.DefaultHighlightColorIndex = wdYellow

To this
'highlight green words
Options.DefaultHighlightColorIndex = wdGreen

and add
vFindText = Array("Next word", "Next word", "Next word")
Reply With Quote
  #10  
Old 07-01-2013, 12:39 PM
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

If you want post your document and let me look at it and let me know the specifics you want added and see what I can do for you.
Reply With Quote
Reply

Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
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 Find and highlight multiple words in MS Word document AtaLoss Word VBA 33 10-10-2017 01:35 AM
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


All times are GMT -7. The time now is 09:33 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