Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 11-03-2013, 03:42 PM
bertietheblue bertietheblue is offline Macro to highlight 100s of proper nouns Windows 7 64bit Macro to highlight 100s of proper nouns Office 2003
Advanced Beginner
Macro to highlight 100s of proper nouns
 
Join Date: May 2012
Location: United Kingdom
Posts: 54
bertietheblue is on a distinguished road
Default Macro to highlight 100s of proper nouns

Hi

I received a lot of help on here before from Big0, who came up with a macro (below) to highlight a list of proper nouns and phrases. It works fine but I just need to make a couple of tweaks:

- I can only put a limited number of terms in the find text array - I need many 100s (I've just left 'England' in the below for ease of reading; I can add about 60-70 terms without being unable to add more)
- I need to put some phrases with brackets in them into the array, but it doesn't allow this at present.



Any help adapting slightly would be appreciated.

Thanks
Bertie
Code:
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("England")
vReplText = "^&"
With Selection.Find
  .Forward = True
  .Wrap = wdFindContinue
  .MatchWholeWord = True
  .MatchWildcards = False
  .MatchSoundsLike = False
  .MatchAllWordForms = False
  .Format = True
  .MatchCase = True
  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

Last edited by macropod; 11-03-2013 at 03:48 PM. Reason: Added code tags & formatting
Reply With Quote
  #2  
Old 11-03-2013, 03:57 PM
macropod's Avatar
macropod macropod is offline Macro to highlight 100s of proper nouns Windows 7 32bit Macro to highlight 100s of proper nouns Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,963
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

Try something based on:
Code:
Sub ReplaceList()
Application.ScreenUpdating = False
Dim vFindText As Variant, i As Long
'highlight red words
Options.DefaultHighlightColorIndex = wdRed
vFindText = "England,France"
vFindText = vFindText & ",New Zealand,Zambia"
vFindText = Split(vFindText, ",")
With ActiveDocument.Content.Find
  .ClearFormatting
  .Replacement.ClearFormatting
  .Forward = True
  .Wrap = wdFindContinue
  .MatchWholeWord = True
  .MatchWildcards = False
  .MatchSoundsLike = False
  .MatchAllWordForms = False
  .Format = True
  .MatchCase = True
  .Replacement.Text = "^&"
  .Replacement.Highlight = True
  For i = LBound(vFindText) To UBound(vFindText)
    .Text = vFindText(i)
    .Execute Replace:=wdReplaceAll
  Next i
End With
Application.ScreenUpdating = True
End Sub
PS: When posting code, please use the code tags. They're on the 'Go Advanced' tab.
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #3  
Old 11-03-2013, 04:22 PM
bertietheblue bertietheblue is offline Macro to highlight 100s of proper nouns Windows 7 64bit Macro to highlight 100s of proper nouns Office 2003
Advanced Beginner
Macro to highlight 100s of proper nouns
 
Join Date: May 2012
Location: United Kingdom
Posts: 54
bertietheblue is on a distinguished road
Default

Thanks, macropod and sorry I didn't know about the code tags, but will add in future.

Could I ask 2 quick questions re the code:

(a) Do I put as many terms as will fit into:
Code:
vFindText = "England,France"
And then continue in:
Code:
vFindText = vFindText & ",New Zealand,Zambia"
And then if that runs out, copy and paste the above to create a 3rd vFindText line (my current list runs to well over 500 terms so I imagine I need quite a few lines)?

(b) I need spaces in some terms so only whole words are found, eg 'An ' - do I just put a space before the following comma?
Reply With Quote
  #4  
Old 11-03-2013, 04:32 PM
macropod's Avatar
macropod macropod is offline Macro to highlight 100s of proper nouns Windows 7 32bit Macro to highlight 100s of proper nouns Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,963
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

RE: a
I'd limit the number of entries on each line to what you can see without scrolling in the VBA editor, perhaps even somewhat less than that. You can simply keep adding more:
vFindText = vFindText & ",Name1,Name2"
lines as needed, before the:
vFindText = Split(vFindText, ",")
line.

RE: b
You don't need the space, as your Find/Replace code already has '.MatchWholeWord = True'. Note that you can already use multi-word expressions, such as 'New Zealand'. The only restriction is that they can't use a comma; otherwise you'll need a different separator character.
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #5  
Old 11-03-2013, 04:56 PM
bertietheblue bertietheblue is offline Macro to highlight 100s of proper nouns Windows 7 64bit Macro to highlight 100s of proper nouns Office 2003
Advanced Beginner
Macro to highlight 100s of proper nouns
 
Join Date: May 2012
Location: United Kingdom
Posts: 54
bertietheblue is on a distinguished road
Default

Thanks, I'll give that a shot tomorrow on the document I'm working on. I've posted another, though related, thread, but I appreciate that you can only answer a limited number of queries.
Reply With Quote
Reply



Similar Threads
Thread Thread Starter Forum Replies Last Post
Macro to highlight 100s of proper nouns Macro to highlight a list of words bakerkr Word VBA 4 10-19-2017 02:23 PM
Macro to highlight 100s of proper nouns Macro to highlight words bertietheblue Word VBA 9 07-01-2013 12:39 PM
Macro to highlight 100s of proper nouns Macro to highlight text between 2 points in word 2010 jsilva1950 Word VBA 2 04-25-2013 12:21 AM
Trying to highlight pasted text in a macro goldengate Word VBA 0 09-14-2010 09:41 PM
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 11:45 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