View Single Post
 
Old 10-01-2025, 09:49 PM
calinanix calinanix is offline Windows 11 Office 2021
Novice
 
Join Date: Sep 2025
Posts: 7
calinanix is on a distinguished road
Default

Hi Greg!


Thank you for taking the time to write the code, and sorry for the late reply.


The code works wonderfully! I did make the initial mistake of inserting it to the Excel file, and later figured out that the macro should run from the Word file


May I ask why we need a Listbox object to hold data and what the xlFillList function does? Does the code performance differ from Paul's method which defined the column address in Excel (snippets below)? I would like to learn and understand the code better
Code:
         ' Capture the F/R data.
        For i = 1 To iDataRow
          ' Skip over empty fields to preserve the underlying cell contents.
          If Trim(.Range("A" & i)) <> vbNullString Then
            xlFList = xlFList & "|" & Trim(.Range("A" & i))
            xlRList = xlRList & "|" & Trim(.Range("B" & i))
          End If
        Next


'Some code here


    'Process each word from the F/R List
    With wdDoc
    Options.DefaultHighlightColorIndex = wdYellow
      With .Range.Find
        .ClearFormatting
        .Replacement.ClearFormatting
        .Replacement.Highlight = True
        .MatchWholeWord = True
        .MatchCase = True
        .Wrap = wdFindContinue
        For i = 1 To UBound(Split(xlFList, "|"))
          .Text = Split(xlFList, "|")(i)
          .Replacement.Text = Split(xlRList, "|")(i)
          .Execute Replace:=wdReplaceAll
        Next
      End With
Reply With Quote