Deleting all hyperlinks from a Microsoft Word document

Discussion in 'Windows' started by pradeep, Feb 28, 2007.

  1. pradeep

    pradeep Team Leader

    Apr 4, 2005
    Likes Received:
    Trophy Points:
    Kolkata, India
    Home Page:
    Tired of getting Microsoft Office documents (Word, Excel, Powerpoint) that are chock-full of hyperlinks that are bright blue and easy to accidentally click, making Word goes berserk and open the link?

    You can easily remove all those pesky URLs with a simple macro to remove all the hyperlinks in a document in one full swoop. With macros available to you in one keystroke (Alt F8) this is quite a convenient way of managing your logic ACROSS all Office software — the basic logic remains the same. Let's see some code now:

    1. From a Word document, press ALT F11 to open the MS Visual Basic.
    2. The Visual Basic interface will open up. From the INSERT menu, click on MODULE to add a module.
    3. A new document opens up. In there, paste the following code:

          Sub RemoveHyperLinksGLobally()
               Dim i As Integer
               For i = ActiveDocument.Hyperlinks.Count To 1 Step -1
               Next i
           End Sub
    4. Press CTRL S to save this module.
    5. Now, from the FILE menu, select "CLOSE AND RETURN TO MICROSOFT WORD".
    6. When back into your Word document, now just press ALT F8 to bring up the MACROS selection window (or you can always do TOOLS —> MACRO —> MACROS)

    Our macro is added.
    Not to worry, this does not delete the text, it just converts the hyperlink fields to plain text. However, if your original hyperlink had some formatting and you don't want to lose that formatting for the text, but just want to get rid of the underlying URL, here's some handy code for that too:

    Sub RemoveHyperLinksGLoballyButPreserveCharacterStyle()
         Dim i As Long, myRange As Range
         For i = ActiveDocument.Hyperlinks.Count To 1 Step -1
             With ActiveDocument.Hyperlinks(i)
                 Set myRange = .Range
                 myRange.Style = wdStyleHyperlink
             End With
         Next i
     End Sub
    TIP: Microsoft Word also has the "function" to auto-convert any text you type, that looks like a URL, into a hyperlinked URL. If you want to prevent this, select TOOLS —> AUTOCORRECT —> AUTOFORMAT AS YOU TYPE, and under "Replace as you type", turn off "Internet and network paths with hyperlinks".

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice