Extract Links From Word

Sub ExtractURL()
'
' ExtractURL Macro
'
'

Dim oHpl As Hyperlink
Dim dAD As Document 'active document
Dim dDc2 As Document 'new document
Dim rngStory As StoryRanges
Dim rng As Range
Dim intFootnotes As Integer

    Set dAD = ActiveDocument
    Set dDc2 = Documents.Add
    Selection.TypeText "Hyperlinks found in main document story: " & dAD.StoryRanges(wdMainTextStory).Hyperlinks.Count
    Selection.TypeParagraph
    Set rng = dDc2.Range
    rng.Collapse wdCollapseEnd
    For Each oHpl In dAD.StoryRanges(wdMainTextStory).Hyperlinks
        oHpl.Range.Copy
        dDc2.Activate
        Selection.Paste
        Selection.TypeParagraph
    Next
    On Error Resume Next
    intFootnotes = dAD.StoryRanges(wdFootnotesStory).Hyperlinks.Count
    On Error GoTo 0
    If intFootnotes = 0 Then
        Selection.TypeText "Hyperlinks found in Footnotes: 0"
    Else
        Selection.TypeText "Hyperlinks found in Footnotes: " & dAD.StoryRanges(wdFootnotesStory).Hyperlinks.Count
        Selection.TypeParagraph
        For Each oHpl In dAD.StoryRanges(wdFootnotesStory).Hyperlinks
            oHpl.Range.Copy
            dDc2.Activate
            Selection.Paste
            Selection.TypeParagraph
        Next
    End If
    dDc2.SaveAs "h:hyperlinks.docx"
    Set dAD = Nothing
    Set dDc2 = Nothing
End Sub

Originally Posted on March 13, 2014
Last Updated on October 26, 2015
All information on this site is shared with the intention to help. Before any source code or program is ran on a production (non-development) system it is suggested you test it and fully understand what it is doing not just what it appears it is doing. I accept no responsibility for any damage you may do with this code.