Please Note: This article is written for users of the following Microsoft Word versions: 97, 2000, 2002, and 2003. If you are using a later version (Word 2007 or later), this tip may not work for you. For a version of this tip written specifically for later versions of Word, click here: Removing HTTP from URLs.
by Allen Wyatt
(last updated February 16, 2013)
Graham is a copyeditor and one of the (quite usual) tasks he faces is to remove http:// from URLs that start http://www. Graham finds this task easy if the URL is just text. However, if it is a hyperlink he has to display the Edit Hyperlink dialog box, select http:// in the Text to Display field, delete it, and close the dialog box.
Fortunately, you don't have to always display the Edit Hyperlink dialog box to make your changes. Even if a hyperlink is active, you can find and replace information in what is displayed. For instance, doing a search for http://www and replacing it with www will work just fine, even for active hyperlinks. Word changes just the text that is displayed and not the underlying hyperlink itself.
If you have many, many hyperlinks to edit and this truncation of URLs is a common task, you may want to use a macro to handle this. You can develop a short macro that will step through each hyperlink in the document and remove the http:// portion. The following is an example:
Sub FixHyperlinks1() Dim hyp As Hyperlink Dim sLink As String For Each hyp In ActiveDocument.Hyperlinks sLink = hyp.Address sLink = replace(strLink, "http://www", "www") hyp.Address = sLink Next hyp End Sub
This approach is probably not as comprehensive as you want, however. It only affects active hyperlinks; it doesn't affect plain-text URLs in your document. If you want to use a more comprehensive approach, you need something that will get rid of all the hyperlinks (you probably don't need them in the document in the first place) and then get rid of the http:// portion. Here's one that will do just that:
Sub FixHyperlinks2() 'Remove hyperlinks With ActiveDocument While .Hyperlinks.Count > 0 .Hyperlinks(1).Delete Wend End With 'Remove http:// Selection.Find.ClearFormatting Selection.Find.Replacement.ClearFormatting With Selection.Find .Text = "http://www" .Replacement.Text = "www" .Forward = True .Wrap = wdFindContinue End With Selection.Find.Execute Replace:=wdReplaceAll End Sub
WordTips is your source for cost-effective Microsoft Word training. (Microsoft Word is the most popular word processing software in the world.) This tip (3833) applies to Microsoft Word 97, 2000, 2002, and 2003. You can find a version of this tip for the ribbon interface of Word (Word 2007 and later) here: Removing HTTP from URLs.
Create Custom Apps with VBA! Discover how to extend the capabilities of Office 2013 (Word, Excel, PowerPoint, Outlook, and Access) with VBA programming, using it for writing macros, automating Office applications, and creating custom applications. Check out Mastering VBA for Office 2013 today!
Need to search for information in a table? Word allows you to easily limit your search to an entire column or row, as ...Discover More
Can you really use Find and Replace to change the case of text in your document? Not really, but that shouldn't stop you from ...Discover More
Need to get rid of all the comments in your document? You can do so by using the regular Find and Replace feature of Word.Discover More
Got a version of Word that uses the menu interface (Word 97, Word 2000, Word 2002, or Word 2003)? This site is for you! If you use a later version of Word, visit our WordTips site focusing on the ribbon interface.