Avatar of andr3wg
andr3wgFlag for Ireland

asked on 

Extract hyperlinks from Word Docs

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.

Microsoft WordVB Script

Avatar of undefined
Last Comment
als315
Avatar of als315
als315
Flag of Russian Federation image

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
Hyperlik-test.xls
Avatar of andr3wg
andr3wg
Flag of Ireland image

ASKER

Hi,

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.

Thanks
Avatar of als315
als315
Flag of Russian Federation image

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
.Range.AutoFormat
For Each oRange In .StoryRanges
Do
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

ASKER CERTIFIED SOLUTION
Avatar of als315
als315
Flag of Russian Federation image

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
Avatar of andr3wg
andr3wg
Flag of Ireland image

ASKER

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
Avatar of andr3wg
andr3wg
Flag of Ireland image

ASKER

Happy days.

That does the job.

Cheers.
Avatar of als315
als315
Flag of Russian Federation image

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
VB Script
VB Script

VBScript (Visual Basic Scripting Edition) is an interpreted scripting language developed by Microsoft that is modeled on Visual Basic, but with some important differences. VBScript is commonly used for automating administrative and other tasks in Windows operating systems (by means of the Windows Script Host) and for server-side scripting in ASP web applications. It is also used for client-side scripting in Internet Explorer, specifically in intranet web applications.

39K
Questions
--
Followers
--
Top Experts
Get a personalized solution from industry experts
Ask the experts
Read over 600 more reviews

TRUSTED BY

IBM logoIntel logoMicrosoft logoUbisoft logoSAP logo
Qualcomm logoCitrix Systems logoWorkday logoErnst & Young logo
High performer badgeUsers love us badge
LinkedIn logoFacebook logoX logoInstagram logoTikTok logoYouTube logo