Thread: [Solved] Need Help Creating Macro
View Single Post
 
Old 10-22-2014, 03:09 PM
macropod's Avatar
macropod macropod is offline Windows 7 64bit 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

Do you have a file containing just the ACCA.101069REG-SIM, ACCA.101070REG-SIM, ACCA.101071REG-SIM, etc. references and their reference text? If so, and if you can organise that into a layout like:
ACCA.101069REG-SIM<tab>Mr. Travel is a U.S. citizen who has been a resident of Germany for five years.
ACCA.101070REG-SIM<tab>Mr. Travel is a U.S. citizen who has been a resident of Spain for five years.
ACCA.101072REG-SIM<tab>Mr. Travel is a U.S. citizen who has been a resident of Portugal for five years.
in a document with just a tab separating the reference from the question, and a paragraph break between entries, the following macro could do it for you:
Code:
Sub BulkFindReplace()
Application.ScreenUpdating = False
Dim FRDoc As Document, FRList, j As Long, StrFnd As String, StrRep As String
 'Load the strings from the reference doc into a text string to be used as an array.
Set FRDoc = Documents.Open("Drive:\FilePath\FindReplaceList.doc")
FRList = FRDoc.Range.Text
FRDoc.Close False
Set FRDoc = Nothing
With ActiveDocument.Range.Find
  .ClearFormatting
  .Replacement.ClearFormatting
  .MatchWholeWord = True
  .MatchCase = True
   'Process each word from the Check List. Tab-delimited strings are assumed, formatted as:
   'Find text <Tab> Replace text
  For j = 0 To UBound(Split(FRList, vbCr)) - 1
    StrFnd = Split(Split(FRList, vbCr)(j), vbTab)(0)
    StrRep = Split(Split(FRList, vbCr)(j), vbTab)(1)
    .Text = StrFnd
    .Replacement.Text = StrFnd & vbCr & StrRep
    .Execute Replace:=wdReplaceAll
  Next
End With
Application.ScreenUpdating = True
End Sub
Simply add the macro to the your document's template, change 'Drive:\FilePath\FindReplaceList.doc' to point to your document containing the list, make the document to be updated the active document, then run the macro.
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote