PDA

View Full Version : Extracting hyperlinks



Alasbabylon
10-06-2008, 09:45 AM
Is there a way to extract all the hyperlinks in a Word document and list them in a table with the Text to Display in col 1 and the hyperlink in Col 2?

macropod
10-06-2008, 02:46 PM
Hi Alasbabylon.

Finding hyperlinks with vba is easy: Simply look for hyperlink fields via the fields collection. Copying & inserting the hyperlink fields (or just their properties) into a table isn't especially difficult either.

What have you tried so far?

Alasbabylon
10-07-2008, 06:35 AM
I haven't really tried anything yet - I don't know where to start. I thought I could do a search, but hyperlinks is not a search field - at least, noit in the Find dialog box. I'm don't have any VBA skills.

macropod
10-08-2008, 09:17 PM
Hi Alasbabylon.

Here's some vba code to get you started. It's even simpler than working through the fields collection. Whn it finds a hyperlink it reports the hyperlink address and screen tip. I haven't included the code to write anything to a table for two reasons:
1. You should spend a bit of time learning how to use vba; and
2. You haven't given enough information about the table (eg does it already exist, if so, where is it, and can I rely on it already having enough rows).

Sub FindHyperlinks()
Dim hLnk As Hyperlink
For Each hLnk In ActiveDocument.Hyperlinks
MsgBox hLnk.Address & vbCrLf & hLnk.ScreenTip
Next hLnk
End SubFor your purposes, you need to replace the message box with the code tho output the same details to the table.