Sub FindReplace(pFind As String, pReplace As String)\n Selection.Find.ClearFormatting\n Selection.Find.Replacement.ClearFormatting\n With Selection.Find\n .Text = pFind\n .Replacement.Text = pReplace\n .Forward = True\n .Wrap = wdFindContinue\n .Format = False\n .MatchCase = False\n .MatchWholeWord = False\n .MatchWildcards = False\n .MatchSoundsLike = False\n .MatchAllWordForms = False\n End With\n Selection.Find.Execute Replace:=wdReplaceAll\nEnd Sub\n\n\nSub Find(pFind As String)\n Selection.Find.ClearFormatting\n With Selection.Find\n .Text = pFind\n .Replacement.Text = ""\n .Forward = True\n .Wrap = wdFindContinue\n .Format = False\n .MatchCase = False\n .MatchWholeWord = False\n .MatchWildcards = False\n .MatchSoundsLike = False\n .MatchAllWordForms = False\n End With\n Selection.Find.Execute\nEnd Sub
In a VB program I get the data from Oracle then use the macros as follows:
\n Public gApp As Word.Application\n Dim wDoc As Word.Document\n\n Set gApp = New Word.Application\n Set wDoc = gApp.Documents.Open(OriginalLetter, , True)\n\n Call gApp.Run("FindReplace", "<DATE>", Format(Date, "Long Date"))\n\n Call gApp.Run("Find", "<CUSTOMER_INFO>")\n gApp.Selection.TypeText Address(pCust, pLoc)\n \n Call gApp.Run("FindReplace", "<ACCOUNT_REP>", AccountRep("1", pCust, pLoc))\n Call gApp.Run("Find", "<LATE_INVOICES>")\n \n gApp.Selection.PageSetup.LeftMargin = InchesToPoints(1)\n gApp.Selection.PageSetup.RightMargin = InchesToPoints(1)\n\n gApp.Selection.ParagraphFormat.TabStops.Add InchesToPoints(0.2), wdAlignTabLeft\n gApp.Selection.ParagraphFormat.TabStops.Add InchesToPoints(0.9), wdAlignTabLeft\n gApp.Selection.ParagraphFormat.TabStops.Add InchesToPoints(1.7), wdAlignTabLeft\n gApp.Selection.ParagraphFormat.TabStops.Add InchesToPoints(3.2), wdAlignTabLeft\n gApp.Selection.ParagraphFormat.TabStops.Add InchesToPoints(4.6), wdAlignTabRight\n gApp.Selection.ParagraphFormat.TabStops.Add InchesToPoints(5.6), wdAlignTabRight\n gApp.Selection.ParagraphFormat.TabStops.Add InchesToPoints(6.5), wdAlignTabRight\n\n ... loop to read data and use gApp.Selection.TypeText to add list of late invoices\n\n wDoc.SaveAs NewLetter, 100 ' 100 = Word 97-2003 & 6.0/95 format\n wDoc.Close