Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 07-17-2019, 04:07 PM
Guessed's Avatar
Guessed Guessed is offline Macro in Word to find specific words? Will be used for good cause (prostate cancer research) Windows 10 Macro in Word to find specific words? Will be used for good cause (prostate cancer research) Office 2016
Expert
 
Join Date: Mar 2010
Location: Canberra/Melbourne Australia
Posts: 4,185
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

I recommend you find a standard way to set up the source info before running the macro. Based on what you have said and the sample doc you posted, I would setup the document to start with a two column table, the first column would be filled with the key search terms and the second column would be empty waiting for the macro to run. Then following the table you could paste in the content from your EMR.

The macro that suits this layout and workflow might then look like this.


Code:
Sub Extractor()
  Dim oRng As Range, oTable As Table, oCell As Cell, oNextCell As Cell
  Dim sFind As String, oRngCell As Range
  
  Set oTable = ActiveDocument.Tables(1)
  Set oRng = ActiveDocument.Range(oTable.Range.End, ActiveDocument.Range.End)
  For Each oCell In oTable.Columns(1).Cells
    sFind = Split(oCell.Range.Text, vbCr)(0)
    Set oRngCell = oCell.Next.Range
    With oRng.Find
      .ClearFormatting
      .Replacement.ClearFormatting
      .MatchWildcards = False
      Do While .Execute(FindText:=sFind)
        oRng.MoveStart Unit:=wdWord, Count:=-2
        oRng.MoveEnd Unit:=wdWord, Count:=4
        oRngCell.InsertBefore oRng & vbCr
        oRng.Collapse direction:=wdCollapseEnd
      Loop
      Set oRng = ActiveDocument.Range(oTable.Range.End, ActiveDocument.Range.End)
    End With
  Next oCell
End Sub
Attached Files
File Type: docm keyword search example.docm (20.5 KB, 15 views)
__________________
Andrew Lockton
Chrysalis Design, Melbourne Australia
Reply With Quote
Reply

Tags
keyword, macro, search



Similar Threads
Thread Thread Starter Forum Replies Last Post
How to find (highlight) two and more words in a list of 75k single words in Word 2010 Usora Word 8 05-29-2018 03:34 AM
Macro in Word to find specific words? Will be used for good cause (prostate cancer research) Macro to search for specific words in a document mike0215 Word VBA 2 11-28-2017 07:25 AM
VBA Word - Find & Apply Styles to Specific Words - Using Case Statement jc491 Word VBA 17 12-26-2015 12:25 PM
Macro in Word to find specific words? Will be used for good cause (prostate cancer research) Need VBA For Macro On How To Remove Specific Words netchie Word VBA 6 08-28-2012 03:37 PM
Macro in Word to find specific words? Will be used for good cause (prostate cancer research) Macro for highlighting specific number of words icsjohn Word VBA 2 12-07-2011 06:44 PM

Other Forums: Access Forums

All times are GMT -7. The time now is 12:41 AM.


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