Extract hyperlinks from Word Docs

andr3wg used Ask the Experts™
Hi there,

I've a batch of word docs that contain hyperlinks to image files. I'd like to extract all the hyperlinks in all word docs to a single text file. The hyperlinks are in tables in some of the word docs - if that makes a difference.

Is there an easy way I can achieve this?

Thanks very much.

Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
If it is table and cell contain only hyperlink, may be you can insert it into excel? In this case you can write simple function, which  will show only hyperlinks
Example with function is included



Thanks for that - the word doc has hyperlinks in paragraphs, word tables, lists etc - they're all over the place in it.

I was thinking maybe a script in word to trawl the doc and export out but I'd prefer one work on a batch of word docs rather than individually.

You can use this macro for saving hyperlinks to separate text file:
Sub Macro1()
Dim oFld As Field
Dim oCount As Integer
Dim oRange As Word.Range
Open "c:\tmp\hyperlinks.txt" For Output As #1
oCount = 0
With ActiveDocument
For Each oRange In .StoryRanges
For Each oFld In oRange.Fields
If oFld.Type = wdFieldHyperlink Then
    'MsgBox ActiveDocument.Hyperlinks.Item(oFld.Index).TextToDisplay, vbOKOnly, oCount = oCount + 1
    Write #1, ActiveDocument.Hyperlinks.Item(oFld.Index).TextToDisplay
    oCount = oCount + 1
End If
Next oFld
Set oRange = oRange.NextStoryRange
Loop Until oRange Is Nothing
Next oRange
Close #1
MsgBox "Total Detected HyperLinks=" & oCount
End With
End Sub

Open in new window

Why Diversity in Tech Matters

Kesha Williams, certified professional and software developer, explores the imbalance of diversity in the world of technology -- especially when it comes to hiring women. She showcases ways she's making a difference through the Colors of STEM program.

Change file open string to (correct file path, of course):
Open "c:\tmp\hyperlinks.txt" For Append As #1
if you like to save hyperlinks from more then one file.


Hey als315,

Thanks for the macro - that works perfectly on individual files - thanks.

Do you know if there's a way I can automate or run this macro on multiple docs and export the hyperlinks to the one file?

I have lots of word doc I need to perform this operation on.

Thanks very much


Happy days.

That does the job.

You can open all doc files in a folder and run this macro. Here are many examples. May be not for word, but VBA is same for all office

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial