View Single Post
 
Old 07-17-2019, 04:07 PM
Guessed's Avatar
Guessed Guessed is offline Windows 10 Office 2016
Expert
 
Join Date: Mar 2010
Location: Canberra/Melbourne Australia
Posts: 3,977
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, 13 views)
__________________
Andrew Lockton
Chrysalis Design, Melbourne Australia
Reply With Quote