by Allen Wyatt
(last updated July 14, 2018)
Annemieke has a document that is rather long and it includes a good number of hyperlinks. She would like to copy all those hyperlinks (and just the hyperlinks) to a brand-new document so that she has a list of them in one place. She wonders if there is an easy way to do this.
The only way to do this is to use a macro. (Suggestions that include using Find and Replace or finding text with specific styles will copy only the link text, not the actual hyperlink.) The key in the macro is to work with the Hyperlinks collection, paying particular attention to the TextToDisplay and Address properties of each member of the collection.
Sub PullHyperlinks() Dim Src As Document Dim Link As Hyperlink Dim iDoDisplay As Integer Set Src = ActiveDocument If Src.Hyperlinks.Count > 0 Then iDoDisplay = MsgBox("Include display text for links?", vbYesNo) Documents.Add DocumentType:=wdNewBlankDocument For Each Link In Src.Hyperlinks If iDoDisplay = vbYes Then Selection.TypeText Link.TextToDisplay Selection.TypeText vbTab End If Selection.TypeText Link.Address Selection.TypeParagraph Next Link Else MsgBox "There are no hyperlinks in this document." End If End Sub
The macro first checks to see if there are any hyperlinks in the current document. If there are, then the process of pulling them out can proceed; if there aren't, then a message is displayed to that effect.
Assuming there are hyperlinks in the document, the user is asked if the new document should contain the display text for the links. The macro then creates a new document and steps through each member of the Hyperlinks collection. The value of the TextToDisplay property is added to the new document (if appropriate) followed by the value of the Address property.
WordTips is your source for cost-effective Microsoft Word training. (Microsoft Word is the most popular word processing software in the world.) This tip (13549) applies to Microsoft Word 2007, 2010, 2013, 2016, 2019, and Word in Office 365.
Do More in Less Time! Are you ready to harness the full power of Word 2013 to create professional documents? In this comprehensive guide you'll learn the skills and techniques for efficiently building the documents you need for your professional and your personal life. Check out Word 2013 In Depth today!
Adding a hyperlink to a text selection is easy to do in Word. All you need to do is make a couple of clicks and specify ...Discover More
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
Wouldn't it be great if Word allowed you to have a small pop-up that showed you some information associated with a ...Discover More
FREE SERVICE: Get tips like this every week in WordTips, a free productivity newsletter. Enter your address and click "Subscribe."
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.