Can someone write a writer macro for me? I’ll donate $100 to LibreOffice
Document 1 has two column table. Column 1 is “find” string. Column 2 is “replace” string. The find string would not be longer than 16 to 20 characters. The replace string might be 512 characters but I realize there might a limit of 256.
Document 2 is the working document. The macro called from macro 2 will find and replace all the items in document 2 using document 1 table.
I found this Word macro as a reference. I am trying to migrate my one-man company away from Word
Sub ReplaceFromTableList3()
Dim oChanges As Document, oDoc As Document
Dim oTable As Table
Dim oRng As Range
Dim rFindText As Range, rReplacement As Range
Dim I As Long
Dim sFname As String
'Change the path in the line below to reflect the name and path of the table document
sFname = "C:\reports\wreports\nameoffilewithfindreplacetable.doc"
Set oDoc = ActiveDocument
Set oChanges = Documents.Open(FileName:=sFname, Visible:=False)
Set oTable = oChanges.Tables(1)
For I = 1 To oTable.Rows.Count
Set oRng = oDoc.Range
Set rFindText = oTable.Cell(I, 1).Range
rFindText.End = rFindText.End - 1
Set rReplacement = oTable.Cell(I, 2).Range
rReplacement.End = rReplacement.End - 1
Selection.HomeKey wdStory
With oRng.Find
.ClearFormatting
.Replacement.ClearFormatting
.Replacement.Font.Color = wdColorauto
.MatchWildcards = False
.MatchWholeWord = True
.MatchCase = False
.Text = rFindText.Text
.Replacement.Text = rReplacement.Text
.Forward = True
.Wrap = wdFindContinue
.Execute Replace:=wdReplaceAll
End With
Next I
oChanges.Close wdDoNotSaveChanges
End Sub