Checking Hyperlinks

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


Kyle has a document that includes quite a few hyperlinks to web pages. He wonders if there is a way to automatically validate all of the hyperlinks to make sure they are still active and not broken.

The internet is nothing if not a fluid place. Websites come and go, and links to those websites change all the time. Indeed, there is no guarantee that a link that works today will still work tomorrow. Those who run websites understand this and often spend considerable time checking links and fixing those that no longer work properly.

When it comes to Word documents, though, checking links can be a challenge. If your document has just a few links, the easiest way to check them is to just click on the link (or Ctrl+click) and see what comes up. Kyle, though, indicated that his document has quite a few hyperlinks, and following the manual approach can be tedious, at best.

Since webmasters do link checking so often, there are many tools and services that can be used for checking websites. This means you could save your Word document as an HTML file, open it in your favorite web browser, and then use a link-checking service or extension. You can find such extensions by doing a web search for "link checker browser extension," without the quote marks.

A great way to check links is to do so using a macro. The following is one approach that could be used:

Sub CheckHyperlinks()
    Dim hl As Hyperlink
    Dim http As Object
    Dim iGood As Integer
    Dim iBad As Integer
    Dim sResult As String
    Dim sMsg As String

    On Error Resume Next
    Set http = CreateObject("WinHttp.WinHttpRequest.5.1")
    If http Is Nothing Then
        MsgBox "WinHTTP service not available", vbCritical
        Exit Sub
    End If

    Application.ScreenUpdating = False
    iGood = 0
    iBad = 0
    For Each hl In ActiveDocument.Hyperlinks
        sResult = ""
        If Left(hl.Address, 4) = "http" Then
            http.Open "GET", hl.Address, False
            http.SetRequestHeader "User-Agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36"
            http.Send

            iBad = iBad + 1    ' Assume link is bad
            If Err.Number <> 0 Then
                sResult = "Site connection failure"
                Err.Clear
            Else
                Select Case http.Status
                    Case 200:
                        ' Link is good, so adjust counts
                        iBad = iBad - 1
                        iGood = iGood + 1
                        ' Remove the apostrophe from the following line
                        ' if you want good links commented
                        ' sResult = "OK"
                    Case 404: sResult = "Broken (404 - ?? ????)"
                    Case 403: sResult = "Rejected (403 - blocked)"
                    Case Else: sResult = "Status code: " & http.Status
                End Select
            End If

            If sResult > "" Then
                ActiveDocument.Comments.Add Range:=hl.Range, Text:=sResult
            End If
        End If
    Next hl
    sMsg = "Finished!" & vbCr
    sMsg = sMsg & "Good links: " & iGood & vbCr
    sMsg = sMsg & "Bad links: " & iBad

    Application.ScreenUpdating = True
    MsgBox sMsg, vbInformation
End Sub

The macro steps through each hyperlink in the document and, if it begins with "http," checks to see if the site or page can be reached. If it cannot, then the error code is attached to the link using a comment. When the macro is done, it displays a summary of how many links were checked and the findings.

WordTips is your source for cost-effective Microsoft Word training. (Microsoft Word is the most popular word processing software in the world.) This tip (517) 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

Calculating an IRR with Varying Interest Rates

You might wonder how you can calculate an IRR (internal rate of return) when the person repaying the loan pays different ...

Discover More

Personal Workbook Fails to Load

The Personal workbook is special; it is where you can store macros you want to use all the time in Excel. What do you do, ...

Discover More

Inserting an Image On a Specific Page

Macros are great for processing a document just the way you want. You can even use them to insert graphics, as described ...

Discover More

Create Custom Apps with VBA! Discover how to extend the capabilities of Office 365 applications with VBA programming. Written in clear terms and understandable language, the book includes systematic tutorials and contains both intermediate and advanced content for experienced VB developers. Designed to be comprehensive, the book addresses not just one Office application, but the entire Office suite. Check out Mastering VBA for Microsoft Office 365 today!

More WordTips (ribbon)

Editing a Hyperlink

Word allows you to embed active hyperlinks in your documents. If you later want to change or edit that hyperlink, you can ...

Discover More

Changing from Absolute to Relative Hyperlinks

It is easy to amass a large number of hyperlinks in a document. You may want to process these hyperlinks in some way, ...

Discover More

Replacing Plain Text with a Hyperlink

Active hyperlinks can be a desired feature in some types of documents. If you want to replace multiple instances of plain ...

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 minus 0?

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.