Need to find and move url text to another word document

I need to find url text(with & without hyperlink) using multiple type of RegEx then if it's found import all url text to new word document from current active document. Is it possible in word VBA? Can anyone ​suggest code?
RegEx Types
Type 1: with https://
Type 2: without https://
Type 3: with www.
Type 4: without www.
Steven ReynoldsAsked:
Who is Participating?
 
Rgonzo1971Connect With a Mentor Commented:
Hi,

pls try
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)
    Next
    Documents.Add
    ActiveDocument.Range.Text = Join(arrSentences, vbCrLf)
Set regex = Nothing
End Sub

Open in new window

Regards
0
 
Steven ReynoldsAuthor Commented:
Hi Rgonzo1971
Thank you for your assist. Above code is working well but I need to retain paragraph style, font forecolor, & bold style as per original document. Is it possible?
0
 
Steven ReynoldsAuthor Commented:
I need to retain all styles like paragraph style, list style, etc., & font colors, & bold style as per original document. Is it possible?
0
 
Rgonzo1971Commented:
Sorry can't help further
0
 
Rgonzo1971Commented:
A Solution
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.