Word Hacks [Electronic resources]

Andrew Savikas

نسخه متنی -صفحه : 162/ 53
نمايش فراداده

Hack 28 Unlink Every Hyperlink

Sometimes uninvited, often distracting, and always hard to wrangle, hyperlinks tend to stick around your documents like unwelcome guests at a party. Here's how to show them the door.

Maybe it's because they're so difficult to edit; maybe it's the tacky combination of blue and underline; or maybe it's having to continually dismiss that web browser or email editor you didn't mean to open. Whatever the reason, many users have just one thing to say about hyperlinks in Word: "How do I get rid of them!?"

To stop Word from creating hyperlinks, select ToolsAutoCorrect Options (ToolsAutoCorrect in Word 97 and 2000), click the "AutoFormat As You Type" tab, and uncheck the "Internet and network paths with hyperlinks" box.

To unlink a single hyperlink, select it, then right-click and choose Remove Hyperlink from the shortcut menu, as shown in Figure 4-5.

Figure 4-5. Removing a hyperlink with the Hyperlink shortcut menu

You can also unlink a hyperlink by selecting it and then pressing Ctrl-Shift-F9. However, this key command unlinks all the fields in the current selection. So selecting all the text in your document and then pressing Ctrl-Shift-F9 would remove all the hyperlinks and unlink every other field in your document, making it a poor choice for the task at hand.

Word offers no built-in way to unlink just every hyperlink in a document all at once. However, you can use a macro to get the job done.

4.3.1 The Code

Place this macro in the template of your choice [Hack #50] and either run it from the ToolsMacroMacros dialog or put a button for it on a menu or toolbar [Hack #1].

Running the following macro achieves the same result as selecting each hyperlink and choosing Remove Hyperlink from the shortcut menu:

Sub RemoveAllHyperlinks( )
Dim i As Integer
For i = ActiveDocument.Hyperlinks.Count To 1 Step -1
ActiveDocument.Hyperlinks(i).Delete
Next i
End Sub

Notice that while the shortcut menu uses the term "remove," in this macro, each hyperlink is "deleted." Though the terminology is inconsistent, the result is the same: the text remains in your document, but it is no longer an active hyperlink and no longer appears as blue and underlined.

You may want to add this macro to the Hyperlink shortcut menu [Hack #3].

4.3.2 Hacking the Hack

When a hyperlink is inserted into your document (either manually or automatically), the Hyperlink character style is applied to its text. The Hyperlink character style is just like any other character style in Word. You can see it displayed in the Styles pull-down menu on the Formatting toolbar, as shown in Figure 4-6.

Figure 4-6. Hyperlink is just another built-in character style

If you like having the links but can't stand the blue underlining, you can change it. Select FormatStyles and Formatting (FormatStyle in Word 2000), choose the Hyperlink style, and click the Modify button. Next, click the Format button and choose Font. The Font dialog, shown in Figure 4-7, lets you change the style to suit your tastes.

Figure 4-7. Choosing a more mellow format for Word hyperlinks

If you remove a hyperlink, the Hyperlink character style goes with it. The reverse, however, is not truethat is, if you select a hyperlink and alter its styling (e.g., remove the underlining), you will still be left with a fully "clickable" hyperlink.

You can apply any style or formatting you like to a hyperlink, and it will remain active. But if you apply the Hyperlink style to regular text, it won't create a hyperlink (though its appearance will certainly confuse you).

If you want to remove all the hyperlinks in a document but keep the Hyperlink character style applied to the text, modify the macro as follows:

Sub RemoveHyperlinksKeepStyle( )
Dim oHyperlink As Hyperlink
Dim i As Integer
Dim rng As Range
For i = ActiveDocument.Hyperlinks.Count To 1 Step -1
Set oHyperlink = ActiveDocument.Hyperlinks(i)
Set rng = oHyperlink.Range
oHyperlink.Delete
rng.Style = wdStyleHyperlink
Next i
End Sub

To completely remove all the hyperlinks in a document, including their text, change the RemoveAllHyperlinks macro to the following:

Sub ReallyRemoveAllHyperlinks( )
Dim i As Integer
For i = ActiveDocument.Hyperlinks.Count To 1 Step -1
ActiveDocument.Hyperlinks(i).Range.Delete
Next i
End Sub