Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 06-22-2015, 09:45 AM
tvincent8118 tvincent8118 is offline Multiple keyword search in WORD Windows 7 64bit Multiple keyword search in WORD Office 2010 32bit
Novice
Multiple keyword search in WORD
 
Join Date: Jun 2015
Posts: 1
tvincent8118 is on a distinguished road
Red face Multiple keyword search in WORD

Hello, I am trying to create a Macro in WORD 2010 to be able to search documents for multiple keywords at once and highlight them, but some of the keywords are medical abbreviations so I don't want it to highlight when those letters are part of another word. I am new to the use of Macros. In my search to try to find out how to do this, I learned about Visual Basic for Applications (or better said, saw it). I copied the following and it worked but I have two issues:


1. The aforementioned highlighting of instances where letters are part of a WORD and...
2. I need to know how to create this is such a way that it is available on all documents and I can add a button to the Toolbar that will run it on any document I so choose.
Here's what I did in VBA
Code:
Sub TBI1()
Dim range As range
Dim I As Long
Target List = Array(“TBI”, “Brain”, “face”, “facial”, “CT”, “MRI”, “traumatic”, “subdural”, “cranial”, “cranium”, “deficit”, “GCS”, “LOC”, “consciousness”, “head”, “memory”, “concussion”, “executive”)
For I = 0 To UBound(TargetList)
  Set range = ActiveDocument.range
  With range.Find
    .Text = TargetList(I)
    .Format = True
    .MatchCase = True
    .MatchWholeWord = False
    .MatchWildcards = False
    .MatchSoundsLike = False
    .MatchAllWordForms = False
    Do While .Execute(Forward:=True) = True
      range.HighlightColorIndex = wdYellow
    Loop
  End With
Next
End Sub
Any help would be greatly appreciated. Thanks

Last edited by macropod; 06-23-2015 at 04:37 AM. Reason: Added code tags & formatting
Reply With Quote
  #2  
Old 06-23-2015, 04:45 AM
macropod's Avatar
macropod macropod is offline Multiple keyword search in WORD Windows 7 64bit Multiple keyword search in WORD Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,962
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

You can avoid partial-word matches by changing:
.MatchWholeWord = False
to:
.MatchWholeWord = True

To make the macro available to all documents, you could add it to Word's Normal template.

Word 2007 & later don't have toolbars, though you could add a button to, say, the Add-ins tab on the Ribbon. For advice on that, see: http://gregmaxey.com/word_tip_pages/...bbon_main.html
You might find it easier and just as useful to simply assign a keyboard shortcut to the macro. See: http://word.mvps.org/faqs/customizat...roToHotkey.htm

PS: When posting code, please use the code tags, which you can insert via the # button on the posting menu.
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
Reply

Tags
help a novice



Similar Threads
Thread Thread Starter Forum Replies Last Post
search on multiple word documents Guy Roth Word 7 03-06-2017 01:31 PM
VBA find keyword and move to location then add symbol Jmanville Word VBA 3 10-22-2014 01:45 AM
Multiple keyword search in WORD Search Multiple strings and create new word file subodhgupta Word 4 05-22-2014 03:34 AM
Multiple keyword search in WORD Search Multiple strings and create new word sheet subodhgupta Word Tables 1 05-20-2014 08:09 AM
Multiple words, one search return2300 Word VBA 0 08-30-2013 12:26 PM

Other Forums: Access Forums

All times are GMT -7. The time now is 02:07 PM.


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