A friend writes:
I have a document in MS Word .docx Word 2007 with hyperlinked text. That is fine for converting to pdf and e-book formats, but I want to create a printed hard copy version, so I need endnotes for the printed version. Is there a way to convert the hyperlinks to endnotes, numbered as they occur in the document? I understand I might have to then fill in the text/description of the endnote, but at least I’d have the endnote number where the hyperlink was and can fill in the endnote that corresponds to the former hyperlink.
Yes. You can do this with a macro. Macros require assumptions. The first assumption is that you don’t want to eliminate the hyperlink—you want it to continue to work in the document, but you want something in the document that also displays the URL. A second assumption is that the URL currently is not displayed in the text. Otherwise, you wouldn’t really need a macro, since the URL would be plainly visible. As third assumption is that you don’t have hundreds of these to convert. Otherwise, we would need some kind of looping control to run the macro until all of the hyperlinks were converted. A fourth assumption is that you are going to put the insertion point at the beginning of the hyperlink before running the macro. The fifth and final assumption is that you know how to create a macro and to set up macro security so that it works in your environment.
With those assumptions in mind, let’s manually do what the macro will do:
- Move the insertion point to the beginning of the hyperlink.
- Press Ctrl+K, or right-click and choose Edit Hyperlink.
- Select the text in the Address field, and copy it to the clipboard.
- Close the Edit Hyperlink dialog box.
- Select References tab – Insert Endnote.
- Type Source:, and then paste the contents of the clipboard.
- Return the insertion point to its previous location in the text.
I like to record macros. When you try to record this as a macro, however, you discover that the macro recorder doesn’t record anything in steps 2 through 4. So, you either need to use VBA to get the contents of the URL Address field, or you do something else. I’m not a VBA expert, however, so I have no clue how to use VBA to get the contents of the address field. Instead, I use some trickery. I toggle the hyperlink field display on (Shift+F9), then I search for everything between two ” marks… this selects the address. I then copy the selection to the clipboard.
To make a long story short[er], the following macro does all that:
.Text = “”"*”"”
.Replacement.Text = ” ”
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchAllWordForms = False
.MatchSoundsLike = False
.MatchWildcards = True
Selection.MoveRight Unit:=wdCharacter, Count:=3
.Location = wdEndOfDocument
.NumberingRule = wdRestartContinuous
.StartingNumber = 1
.NumberStyle = wdNoteNumberStyleLowercaseRoman
.Endnotes.Add Range:=Selection.Range, Reference:=”"
Selection.TypeText Text:=”Source: ”
Selection.Delete Unit:=wdCharacter, Count:=1
Selection.MoveLeft Unit:=wdCharacter, Count:=3
Important Note: WordPress seems to want to convert straight quotes to directional/smart quotes. Note that all quotes in the above should be straight quotes—not directional quotes.
So, click the Developer tab in Word, then click Macros… and, oh, yeah. Assumption five assumes you know what to do now. If not, there are plenty of already-written macro-how-to instruction manuals online, so that I won’t reinvent that particular wheel here and now. Google is your friend.
Caveat: macros are environment-specific sometimes. So, what works for me right now the way I have Word configured might not work for someone else with a different version of Word or a different configuration. I did this in Word 2010, but I don’t see any reason it shouldn’t work equally well in Word 2007. That said… let me know if it works.