2 Quick Ways to Batch Extract All Hyperlinks from Your Word Document

This article is going to show you 2 quick ways to Batch extract all hyperlinks from your Word document, so as to follow the links.

Every so often, there can be hundreds of hyperlinks scattering all over a Word document. In this scenario, if you need to follow a specific link, you must navigate through the document to find it first, which can be such a pain in a long file.

However, if you export them to a new document, things can get a lot easier. Here are our solutions.

Method 1: Utilize the “Find” Feature

  1. Firstly, click “Home” tab then the arrowhead button near the “Find” command.
  2. On the drop-down menu choose “Advanced Find” to open the “Find and Replace” dialog box.Click "Home"->Click "Find"->Choose "Advanced Find"
  3. Next click “More” button and click “Format”.
  4. Choose “Style” to open “Find Style” box.
  5. Select “Hyperlink” and click “OK”.Click "Format"->Choose "Style"->Choose "Hyperlink"->Click "OK"
  6. Then click “Find In” and choose “Main Document”.Click "Find In"->Choose "Main Document"

You can see all hyperlinks in selection now. However, if you copy and paste them to a new document, you will find links lose their formatting and become plain texts.Hyperlinks lose style

Currently, Microsoft does not have a solution for this issue. So you have to convert plain texts back to hyperlinks again manually. Here is our earlier article, listing various ways you can follow: 5 Ways to Convert URL Texts to Hyperlinks in Your Word Document

Because of this shortcoming, we recommend you another way, also performed with the help of the “Find” feature. Please refer to “Find All Hyperlinks in a Document” section in this article: How to Find, Change and Delete Hyperlinks in Your Word Document

After finding all hyperlinks, you do the “Copy” and “Paste” work to export them.

Method 2: Run VBA Codes

  1. First and foremost, press “Alt+ F11” to open the VBA editor.
  2. Next click “Insert” and choose “Module” to create a new one under the “Normal” project.Click"Normal"->Click "Insert"->Click "Module"
  3. Then double click the module to open editing space and paste the bellowing codes there:
Sub ExtractAllhyperlinksInDoc()
  Dim objDoc As Document, objNewDoc As Document
  Dim objHyperlink As Hyperlink
 
  '  Initialization
  Set objDoc = ActiveDocument
  Set objNewDoc = Documents.Add
 
  '  Copy hyperlinks and paste them to a new document.
  With objDoc
    For Each objHyperlink In .Hyperlinks
      objHyperlink.Range.Copy
      objNewDoc.Activate
      With Selection
        .Paste
        .InsertParagraph
        .Collapse Direction:=wdCollapseEnd
      End With
    Next objHyperlink
  End With
End Sub
  1. Lastly, click “Run” button.Paste Codes->Click "Run"

Now there will be a new document open and all hyperlinks are clickable there.

Besides, in case there is a batch of files need to process, you can run this macro bellow:

Sub ExtractHyperlinksFromMultiDoc()
  Dim objDoc As Document, objNewDoc As Document
  Dim objHyperlink As Hyperlink
  Dim strFile As String, strFolder As String
 
  '  Initialization
  Set objNewDoc = Documents.Add
  strFolder = InputBox("Enter folder path here: ", "Folder path")
  strFile = Dir(strFolder & "\" & "*.docx", vbNormal)
 
  '  Open each file in the folder to extract hyperlinks and past them to a new document.
  While strFile <> ""
    Set objDoc = Documents.Open(FileName:=strFolder & "\" & strFile)
 
    With objDoc
      For Each objHyperlink In .Hyperlinks
        objHyperlink.Range.Copy
        objNewDoc.Activate
        With Selection
          .Paste
          .InsertParagraph
          .Collapse Direction:=wdCollapseEnd
        End With
      Next objHyperlink
    End With
    objDoc.Close
    strFile = Dir()
  Wend
End Sub

Remember to arrange all documents in one folder first. Then run the above macro to get an input box. Enter the folder path and click “OK”.Enter Folder Path->Click "OK"

All hyperlinks are now available in a new document.

Ready for Word Errors

No matter how reluctant we are to run into a Word error. It is inevitable to suffer this from time to time. Our suggestion is when Word collapses, choosing a proficient Word repair tool. Just leave everything to the professional.

Author Introduction:

Vera Chen is a data recovery expert in DataNumen, Inc., which is the world leader in data recovery technologies, including xls damage and pdf repair software products. For more information visit www.datanumen.com

4 responses to “2 Quick Ways to Batch Extract All Hyperlinks from Your Word Document”

  1. First off I would like to say great blog! I had a quick question which I’d like to ask if you do not mind. I was curious to find out how you center yourself and clear your mind prior to writing. I have had a difficult time clearing my thoughts in getting my thoughts out. I truly do take pleasure in writing but it just seems like the first 10 to 15 minutes tend to be lost just trying to figure out how to begin. Any ideas or tips? Many thanks!

  2. Right now it appears like WordPress is the preferred blogging platform out there right now. (from what I’ve read) Is that what you’re using on your blog?

  3. this code works only if the URLs are already formatted as hyperlinks.
    More useful would be a code which would, in a first step, identify URLs which are not yet formatted as hyperlinks and formats them as such.
    And then the code above would identify and extract them.

  4. This batch process works on smaller amount of files, but does fail when running this on say over 1000 documents with compile errors and so on. Could be linked to memory usage or potentially the file it is generating is getting too large with the amount of links.

    Would be ideal to output the results to a database table or csv.

Leave a Reply

Your email address will not be published. Required fields are marked *