Generating a List of Hyperlink Targets

Written by Allen Wyatt (last updated September 13, 2025)
This tip applies to Word 2007, 2010, 2013, 2016, 2019, 2021, 2024, and Word in Microsoft 365


Paul has a document that includes many hyperlinks. These are not only in the body of the document, but also in headers, footers, footnotes, and a few text boxes. He would like a way to copy the target addresses of all those hyperlinks to a new document. Paul imagines this must be done with a macro, but he doesn't know how to go about it.

There's actually a way to get hyperlinks into another document without using a macro—at least partially. You can follow these steps:

  1. Open the document from which you want to cull the hyperlinks. (I'll call this the source document.)
  2. Open a new, blank document. (I'll call this the target document.)
  3. Switch back to the source document.
  4. Press Alt+F9. Word displays the field codes instead of the results of field codes.
  5. Press Ctrl+H. Word displays the Replace tab of the Find and Replace dialog box.
  6. Switch to the Find tab.
  7. In the Find What box, enter ^dHYPERLINK.
  8. Select the Highlight All Items In check box.
  9. Click Find All. Word selects all the hyperlinks in the document.
  10. Press Esc to close the Find and Replace dialog box.
  11. Press Ctrl+C. All the hyperlinks are copied to the Clipboard.
  12. Switch to the target document.
  13. Press Shift+Ctrl+V. The text of all of the hyperlinks is pasted into the document.

I say that this process copies hyperlinks "at least partially" because there are notable limitations to it. First, what you are copying is the hyperlink text displayed in the document, not the targets of the hyperlinks. As long as the actual URLs are displayed (when the field results are showing), then you are fine. Plus, the steps won't copy the hyperlinks targets that may be located in other areas, such as headers, footers, footnotes, etc.

Since Paul specifically said he wants the hyperlinks from wherever they may be in the document, then the best solution is to use a macro. This macro should do the job:

Sub ExtractHyperlinks()
    Dim dSource As Document
    Dim dTarget As Document
    Dim h As Hyperlink
    Dim sec As Section
    Dim hdrftr As HeaderFooter
    Dim shp As Shape
    Dim s As Range
    Dim iCount As Integer

    Set dSource = ActiveDocument
    Set dTarget = Documents.Add

    On Error Resume Next

    ' --- Body, footnotes, endnotes ---
    For Each s In dSource.StoryRanges
        Do
            For Each h In s.Hyperlinks
                dTarget.Content.InsertAfter h.Address & vbCr
                iCount = iCount + 1
            Next h
            Set s = s.NextStoryRange
        Loop Until s Is Nothing
    Next s

    ' --- Shapes / text boxes) ---
    For Each shp In dSource.Shapes
        If shp.TextFrame.HasText Then
            For Each h In shp.TextFrame.TextRange.Hyperlinks
                dTarget.Content.InsertAfter h.Address & vbCr
                iCount = iCount + 1
            Next h
        End If
    Next shp

    ' --- Headers/footers may contain shapes too ---
    For Each sec In dSource.Sections
        For Each hdrftr In sec.Headers
            For Each shp In hdrftr.Shapes
                If shp.TextFrame.HasText Then
                    For Each h In shp.TextFrame.TextRange.Hyperlinks
                        dTarget.Content.InsertAfter h.Address & vbCr
                        iCount = iCount + 1
                    Next h
                End If
            Next shp
        Next hdrftr
        For Each hdrftr In sec.Footers
            For Each shp In hdrftr.Shapes
                If shp.TextFrame.HasText Then
                    For Each h In shp.TextFrame.TextRange.Hyperlinks
                        dTarget.Content.InsertAfter h.Address & vbCr
                        iCount = iCount + 1
                    Next h
                End If
            Next shp
        Next hdrftr
    Next sec

    On Error GoTo 0
    MsgBox "Done! Found " & iCount & " hyperlinks."
End Sub

The macro checks everyplace that could contain hyperlinks, and then copies the target of those hyperlinks to a new document. The resulting document lists hyperlinks in no particular order, but they would be easy enough to sort, as desired.

Note:

If you would like to know how to use the macros described on this page (or on any other page on the WordTips sites), I've prepared a special page that includes helpful information. Click here to open that special page in a new browser tab.

WordTips is your source for cost-effective Microsoft Word training. (Microsoft Word is the most popular word processing software in the world.) This tip (13955) applies to Microsoft Word 2007, 2010, 2013, 2016, 2019, 2021, 2024, and Word in Microsoft 365.

Author Bio

Allen Wyatt

With more than 50 non-fiction books and numerous magazine articles to his credit, Allen Wyatt is an internationally recognized author. He is president of Sharon Parq Associates, a computer and publishing services company. ...

MORE FROM ALLEN

Canceling a Menu

Want to back out of whatever you are doing in a menu? As with many tasks, Word provides several different ways you can ...

Discover More

Aligning Cells when Importing from CSV

When you import information from a CSV text file, Excel formats the data according to its default settings. Wouldn't it ...

Discover More

Ranges on Multiple Worksheets

Referring to a range of cells on the current worksheet is easy. But what if you want to refer to a range on a number of ...

Discover More

Learning Made Easy! Quickly teach yourself how to format, publish, and share your content using Word 2021 or Microsoft 365. With Step by Step, you set the pace, building and practicing the skills you need, just when you need them! Check out Microsoft Word Step by Step today!

More WordTips (ribbon)

Changing Hyperlink Display Text

A hyperlink consists, at a minimum, of display text and a target address. Word provides multiple ways you can make ...

Discover More

Adding Hyperlinks

Adding a hyperlink to a text selection is easy to do in Word. All you need to do is make a couple of clicks and specify ...

Discover More

Associating a Name with a Position

Wouldn't it be great if Word allowed you to have a small pop-up that showed you some information associated with a ...

Discover More
Subscribe

FREE SERVICE: Get tips like this every week in WordTips, a free productivity newsletter. Enter your address and click "Subscribe."

View most recent newsletter.

Comments

If you would like to add an image to your comment (not an avatar, but an image to help in making the point of your comment), include the characters [{fig}] (all 7 characters, in the sequence shown) in your comment text. You’ll be prompted to upload your image when you submit the comment. Maximum image size is 6Mpixels. Images larger than 600px wide or 1000px tall will be reduced. Up to three images may be included in a comment. All images are subject to review. Commenting privileges may be curtailed if inappropriate images are posted.

What is three less than 3?

There are currently no comments for this tip. (Be the first to leave your comment—just use the simple form above!)


This Site

Got a version of Word that uses the ribbon interface (Word 2007 or later)? This site is for you! If you use an earlier version of Word, visit our WordTips site focusing on the menu interface.

Videos
Subscribe

FREE SERVICE: Get tips like this every week in WordTips, a free productivity newsletter. Enter your address and click "Subscribe."

(Your e-mail address is not shared with anyone, ever.)

View the most recent newsletter.