Thread: select until =
View Single Post
 
Old 01-30-2024, 01:46 AM
vivka vivka is offline Windows 7 64bit Office 2016
Expert
 
Join Date: Jul 2023
Posts: 302
vivka is on a distinguished road
Default

Hi! What about this simple little code:
Code:
Sub Test_Macro()
'Copy a range from the current para's start till after "=" and
'paste it after the para.

Dim oRng As range
    Set oRng = selection.Paragraphs(1).range
    oRng.Start = oRng.Start - 1
    selection.Find.ClearFormatting
    selection.Find.Replacement.ClearFormatting
    With oRng.Find
        .text = "^13[!^13]@="
        .Replacement.text = ""
        .Forward = True
        .Wrap = wdFindStop
        .Format = False
        .MatchAllWordForms = False
        .MatchSoundsLike = False
        .MatchWildcards = True
        If .Execute Then
            oRng.Start = oRng.Start + 1
            oRng.Copy
            selection.Paragraphs(1).range.Select
            selection.Collapse wdCollapseEnd
            selection.InsertAfter vbCr
            selection.Collapse
            selection.PasteAndFormat (wdFormatOriginalFormatting)
        End If
    End With
End Sub
Note: the macro works starting from the doc's 2nd paragraph.
Reply With Quote