View Single Post
 
Old 06-22-2022, 04:24 AM
macropod's Avatar
macropod macropod is offline Windows 10 Office 2016
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,697
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

Perhaps:
Code:
Sub Demo()
Application.ScreenUpdating = False
Dim StrFnd As String, StrRep As String, i As Long, j As Long, k As Long
StrFnd = "([A-Z]{4}.)([0-9]{4})/([0-9]{4})/([0-9]{4})/([0-9]{4})/([0-9]{4})"
StrRep = "\1\2 \1\3 \1\4 \1\5 \1\6"
j = Len(Split(StrFnd, "/")(1)) + 1: k = Len(Split(StrRep, " ")(0)) + 1
With ActiveDocument.Range
  With .Find
    .ClearFormatting
    .Replacement.ClearFormatting
    .Format = False
    .Forward = True
    .Wrap = wdFindContinue
    .MatchWildcards = True
    For i = UBound(Split(StrFnd, "/")) To 1 Step -1
      .Text = StrFnd
      .Replacement.Text = StrRep
      .Execute
      Do While .Found = True
        .Execute Replace:=wdReplaceAll
      Loop
      StrFnd = Left(StrFnd, Len(StrFnd) - j): StrRep = Left(StrRep, Len(StrRep) - k)
    Next
    .Text = "[A-Z]{4}.[0-9]{4}"
    .Replacement.Text = "[^&]"
    .Execute Replace:=wdReplaceAll
  End With
End With
Application.ScreenUpdating = True
End Sub
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]

Last edited by macropod; 06-22-2022 at 05:23 AM. Reason: Code revision for greater efficiency
Reply With Quote