VBA Style & formatting

I need to retain all styles like paragraph style, list styles, & font colors & bold formatting as per original document while search & move the regex-based text. Pls suggest code if is it possible.

Sub RegexSimple()
Dim regex As Object
Dim arrSentences()
Idx = -1
Set regex = CreateObject("VBScript.RegExp")

    With regex
        .Global = True
        .IgnoreCase = False
        .Pattern = "\b(?:https?:\/\/)?(?:www\.)?(?=\w+\.)[a-zA-Z0-9.\/]+\b"
    End With
    Set Mtchs = regex.Execute(ActiveDocument.Range.Text)
    For Each Mtch In Mtchs
        Idx = Idx + 1
        ReDim Preserve arrSentences(Idx)
        arrSentences(Idx) = Trim(Mtch)
    ActiveDocument.Range.Text = Join(arrSentences, vbCrLf)
Set regex = Nothing
End Sub

Open in new window

Steven ReynoldsAsked:
Who is Participating?
Try using Word's Find object and Copy and Paste the found ranges.
 Note, I am not very fluent in Regex, so I can't be sure what your precise target is, but see how this goes.
Sub CopyFoundRanges()
    Dim docNew As Document
    Dim docA As Document
    Dim rng As Range
    Dim rng2 As Range
    Set docA = ActiveDocument
    Set docNew = Documents.Add
    Set rng = docA.Range
    With rng.Find
        .MatchWildcards = True
        .Text = "https:\/\/www\.[a-zA-Z0-9\-\.]{1,}>"
        Do While .Execute
            Set rng2 = rng.Duplicate
            rng2.Expand wdParagraph
    End With
End Sub

Open in new window

Steven ReynoldsAuthor Commented:
The above code is not working it's only add a new document
All Courses

From novice to tech pro — start learning today.