Word Rename Trainers

SteveD 625 Reputation points
2026-04-14T01:32:08.88+00:00

Hello from Steve

The below script is not Functioning.

What is required please for it to function

Sub Rename_Trainers()

FindArray = Array("RICHARDSON NORV", "D & B WEATHERLE", "THURLOW O'MALLE", "WALKER BERGERSO", "O'SULLIVAN SCOT")

ReplArray = Array("RICHARDSON NORVALL", "D & B WEATHERLEY", "THURLOW O'MALLEY", "WALKER BERGERSON", "O'SULLIVAN SCOTT")

For i = 0 To UBound(FindArray)

    Options.DefaultHighlightColorIndex = wdNoHighlight

    With Selection.Find

        .Font.Size = 14.5

        .Text = FindArray(i)

        .Replacement.Text = ReplArray(i)

        .Replacement.Font.Color = wdColorBlue

        .Forward = True

        .Wrap = wdFindStop

        .Format = True

        .MatchCase = True

        .MatchWholeWord = True

        .MatchWildcards = False

        .MatchSoundsLike = False

        .MatchAllWordForms = False

    End With

    Selection.Find.Execute Replace:=wdReplaceAll

Next i
```End Sub

Developer technologies | Visual Basic for Applications

1 answer

Sort by: Newest
  1. AI answer

    2026-04-14T01:32:18.3233333+00:00

    The macro structure is valid. To make it function reliably, ensure that:

    1. A document is open and the text you want to change is in that document.
    2. The selection is in the main story (not in a header, footer, or another pane) before running the macro.
    3. The Find is fully initialized before each Execute, including clearing previous settings.

    A more robust version based on the documented Find/Replacement pattern is:

    Sub Rename_Trainers()
        Dim FindArray As Variant
        Dim ReplArray As Variant
        Dim i As Long
    
        FindArray = Array("RICHARDSON NORV", "D & B WEATHERLE", "THURLOW O'MALLE", "WALKER BERGERSO", "O'SULLIVAN SCOT")
        ReplArray = Array("RICHARDSON NORVALL", "D & B WEATHERLEY", "THURLOW O'MALLEY", "WALKER BERGERSON", "O'SULLIVAN SCOTT")
    
        Options.DefaultHighlightColorIndex = wdNoHighlight
    
        For i = LBound(FindArray) To UBound(FindArray)
            With ActiveDocument.Content.Find
                .ClearFormatting
                .Replacement.ClearFormatting
    
                .Text = FindArray(i)
                .Replacement.Text = ReplArray(i)
                .Replacement.Font.Color = wdColorBlue
    
                .Forward = True
                .Wrap = wdFindContinue
                .Format = True
                .MatchCase = True
                .MatchWholeWord = True
                .MatchWildcards = False
                .MatchSoundsLike = False
                .MatchAllWordForms = False
    
                .Execute Replace:=wdReplaceAll
            End With
        Next i
    End Sub
    

    Key changes:

    • Uses ActiveDocument.Content.Find so the whole document is searched, independent of the current selection.
    • Calls .ClearFormatting on both Find and Replacement before each run, as shown in the documentation.
    • Uses Wrap:=wdFindContinue so all occurrences in the document are processed.

    If the original code must use Selection.Find, adapt the documented pattern:

    With Selection.Find
        .ClearFormatting
        .Replacement.ClearFormatting
        '... set Text, Replacement.Text, options ...
        .Execute Replace:=wdReplaceAll, Forward:=True, Wrap:=wdFindContinue
    End With
    

    This ensures previous Find settings do not prevent matches and that all instances are replaced.


    References:

    AI-generated content may be incorrect. Read our transparency notes for more information.

    Was this answer helpful?

    1 person found this answer helpful.

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.