Please Note: This article is written for users of the following Microsoft Word versions: 2007, 2010, 2013, 2016, 2019, and Word in Microsoft 365. If you are using an earlier version (Word 2003 or earlier), this tip may not work for you. For a version of this tip written specifically for earlier versions of Word, click here: Removing HTTP from URLs.

Removing HTTP from URLs

Written by Allen Wyatt (last updated August 1, 2020)
This tip applies to Word 2007, 2010, 2013, 2016, 2019, and Word in Microsoft 365


1

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://", "")
        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

Note:

If you would like to know how to use the macros described on this page (or on any other page on the WordTips sites), I've prepared a special page that includes helpful information. Click here to open that special page in a new browser tab.

WordTips is your source for cost-effective Microsoft Word training. (Microsoft Word is the most popular word processing software in the world.) This tip (13147) applies to Microsoft Word 2007, 2010, 2013, 2016, 2019, and Word in Microsoft 365. You can find a version of this tip for the older menu interface of Word here: Removing HTTP from URLs.

Author Bio

Allen Wyatt

With more than 50 non-fiction books and numerous magazine articles to his credit, Allen Wyatt is an internationally recognized author. He is president of Sharon Parq Associates, a computer and publishing services company. ...

MORE FROM ALLEN

Reusing a Bookmark

Bookmarks in Word are just like bookmarks used in paper books, any given bookmark may be reused to mark a new location. ...

Discover More

Including Section Numbers in an Index

When you use Word to create your index, you'll normally only include a page number in the index. If you want to create an ...

Discover More

Getting the Proper Type of Ellipses

Type three periods in a row, and the AutoCorrect feature in Word kicks in to exchange that sequence for a special ...

Discover More

Comprehensive VBA Guide Visual Basic for Applications (VBA) is the language used for writing macros in all Office programs. This complete guide shows both professionals and novices how to master VBA in order to customize the entire Office suite for their needs. Check out Mastering VBA for Office 2010 today!

More WordTips (ribbon)

Quick and Dirty Paragraph Count

Need to know how many paragraphs are in a document? You can use Word's Find and Replace feature to get a count quickly.

Discover More

Making Quoted Text Bold and Underlined

If your document contains quoted text, you might want a way to remove the quotes and format the text in some way. This ...

Discover More

Searching for Optional Hyphens

If you have a document that contains optional hyphens (special characters that mark where a word can be split between ...

Discover More
Subscribe

FREE SERVICE: Get tips like this every week in WordTips, a free productivity newsletter. Enter your address and click "Subscribe."

View most recent newsletter.

Comments

If you would like to add an image to your comment (not an avatar, but an image to help in making the point of your comment), include the characters [{fig}] (all 7 characters, in the sequence shown) in your comment text. You’ll be prompted to upload your image when you submit the comment. Maximum image size is 6Mpixels. Images larger than 600px wide or 1000px tall will be reduced. Up to three images may be included in a comment. All images are subject to review. Commenting privileges may be curtailed if inappropriate images are posted.

What is 1 + 1?

2020-08-21 13:31:52

Peter Johnson

In Sub FixHyperlinks1() the string strLink has not been declared (but sLink has).

Surely the sixth line should read:

sLink = replace(sLink, "http://", "")


This Site

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.

Videos
Subscribe

FREE SERVICE: Get tips like this every week in WordTips, a free productivity newsletter. Enter your address and click "Subscribe."

(Your e-mail address is not shared with anyone, ever.)

View the most recent newsletter.