Share via

Word Not executing cut

SteveD 145 Reputation points
2026-03-12T19:58:53.6866667+00:00

Hello from Steve

Objective is to find .Text = "(*)" then cut and finally

End With

selection.Find.Execute

selection.MoveLeft Unit:=wdCharacter, Count:=5

selection.PasteAndFormat (wdFormatOriginalFormatting)

Sub Move_Barrier()

Dim rng As range

Set rng = ActiveDocument.Content

With rng.Find

.ClearFormatting

.Replacement.ClearFormatting

.Text = "\(*\)"

.Forward = True

.Wrap = wdFindStop

.Format = False

.MatchCase = True

.MatchWholeWord = False

.MatchWildcards = False

End With

Do While rng.Find.Execute

rng.Select

selection.Cut

With selection.Find

    .Text = "[0-9]{1,} [A-Z]"

    .Replacement.Text = ""

    .Forward = True

    .Wrap = wdFindStop

    .Format = False

    .MatchCase = False

    .MatchWholeWord = False

    .MatchAllWordForms = False

    .MatchSoundsLike = False

    .MatchWildcards = True

End With

selection.Find.Execute

selection.MoveLeft Unit:=wdCharacter, Count:=5

selection.PasteAndFormat (wdFormatOriginalFormatting)

selection.TypeText Text:=" "

rng.Collapse wdCollapseEnd

Loop

End Sub

Microsoft 365 and Office | Word | For home | Windows
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Q&A Assist
    2026-03-12T19:59:06.3833333+00:00
    AI generated content. This question contains an answer created with AI from Q&A Assist. Learn more

    The cut is not executed because the first Find does not actually use wildcards, so .Text = "\(*\)" is treated as literal characters instead of a wildcard pattern. As a result, rng.Find.Execute never finds anything and Selection.Cut never runs.

    To make the first Find work with the pattern \(*\) (any text in parentheses), MatchWildcards must be set to True in that With rng.Find block, and the pattern must be a valid Word wildcard expression.

    Key corrections:

    1. Enable wildcards in the first Find:
    With rng.Find
        .ClearFormatting
        .Replacement.ClearFormatting
        .Text = "\(*\)"   ' text in parentheses
        .Forward = True
        .Wrap = wdFindStop
        .Format = False
        .MatchCase = True
        .MatchWholeWord = False
        .MatchWildcards = True   ' was False
    End With
    
    1. Keep the second Find as a wildcard search (it already has .MatchWildcards = True):
    With Selection.Find
        .Text = "[0-9]{1,} [A-Z]"
        .Replacement.Text = ""
        .Forward = True
        .Wrap = wdFindStop
        .Format = False
        .MatchCase = False
        .MatchWholeWord = False
        .MatchAllWordForms = False
        .MatchSoundsLike = False
        .MatchWildcards = True
    End With
    
    1. Use the Range.Find pattern consistently (optional but more robust) instead of switching to Selection inside the loop. For example:
    Do While rng.Find.Execute
        rng.Cut
        ' work with another Range here instead of Selection
        rng.Collapse wdCollapseEnd
    Loop
    

    The essential fix for the cut not firing is setting .MatchWildcards = True in the first Find so that "\(*\)" is recognized as a wildcard pattern and the loop body (including Selection.Cut) is actually reached.


    References:

    You 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.