by Allen Wyatt
(last updated February 15, 2020)
Stephen has a large document (300+ pages) that includes a large number of hyperlinks in the main text. There are, as well, footnotes in the document. Each of the hyperlinks needs to be converted into a footnote, which will (of course) increase the number of footnotes in the document. The increase isn't a problem. The problem is coming up with a fast way to convert all of those hyperlinks to footnotes. Stephen wonders if this could be done using a macro.
This can, indeed, be done with a macro. In fact, the macro may be simpler than you might imagine. Here's an example:
Sub LinksToFootnotes() Dim hLink As Hyperlink Dim rTemp As Range Dim J As Integer For Each hLink In ActiveDocument.Hyperlinks Set rTemp = hLink.Range ' Create footnote ActiveDocument.Footnotes.Add Range:=rTemp, _ Text:=rTemp.Text ' Delete possible leading space rTemp.Collapse rTemp.MoveStart Count:=-1 If rTemp.Text = " " Then rTemp.Delete Next hLink ' Delete hyperlinks For J = ActiveDocument.Hyperlinks.Count To 1 Step -1 ActiveDocument.Hyperlinks(J).Range.Delete Next End Sub
This example does two passes through all the hyperlinks in the document. During the first pass it creates the footnotes and during the second pass it deletes the hyperlinks. Note, as well, that portion of the code that checks to see if there is a space before the hyperlink. This is done so that if there is, that space can be deleted to put the resulting footnote number right next to anything before that space. (In other words, if this wasn't done, it is a good bet that every footnote number would have a space before it.)
That brings up another issue with the macro that you should be aware of—all it does is to create the footnotes and delete the hyperlinks. If there is any information surrounding the original hyperlink (such as parentheses, commas, or periods), those characters will be left in the document. This means that you should do a manual pass through your document after running the macro to make sure that the possible extraneous characters are edited as you want them to be.
Finally, note that the hyperlinks placed into the footnotes are not active hyperlinks—they are text only. This isn't a big issue, though, as plain text is typically what is desired when creating documents that contain footnotes.
WordTips is your source for cost-effective Microsoft Word training. (Microsoft Word is the most popular word processing software in the world.) This tip (13739) applies to Microsoft Word 2007, 2010, 2013, 2016, 2019, and Word in Office 365.
Learning Made Easy! Quickly teach yourself how to format, publish, and share your content using Word 2013. With Step by Step, you set the pace, building and practicing the skills you need, just when you need them! Check out Microsoft Word 2013 Step by Step today!
Jumping to a specific footnote can be very handy if your document has a lot of footnotes in it. Word provides the ...Discover More
When you add a really long footnote to a document, it could be that the entire footnote might not fit on the page where ...Discover More
When using full justification of your text, you may get extra spaces in places you never wanted. This tip examines one ...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.