Deleting all hyperlinks from a Microsoft Office document

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?

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:

A. Microsoft Word

  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
    ActiveDocument.Hyperlinks(i).Delete
    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)

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
.Delete
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”.

B. Microsoft Excel

  1. Same process as a MS Word document. From Excel, fire up the VB editor (ALT F11).
  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 = ActiveSheet.Hyperlinks.Count To 1 Step -1
    ActiveSheet.Hyperlinks(i).Delete
    Next i
    End Sub
  4. The only difference from the code for MS Word is highlighted in green. ActiveSheet, instead of ActiveDocument.
  5. Now, from the FILE menu, select “CLOSE AND RETURN TO MICROSOFT EXCEL”.
  6. When back into your Excel document, now just press ALT F8 to bring up the MACROS selection window (or you can always do TOOLS –> MACRO –> MACROS) and select the right macro. Bingo.

However, since we only work with the “ActiveSheet” in the above example, we remove the hyperlinks only from the single active sheet that is currently on the screen. To remove all the hyperlinks from all the worksheets in an Excel document, this code is handy:

Sub RemoveHyperLinksGLoballyFromAllWorksheets()
Dim i As Integer, wSheet As Worksheet
For Each wSheet In Worksheets
For i = wSheet.Hyperlinks.Count To 1 Step -1
wSheet.Hyperlinks(i).Delete
Next i
Next wSheet
End Sub

Hopefull, this gives you ideas on how to author other macros too. With slight tweaks in code, they can be used across all Office software. Macros are powerful ways of making your editing fast. Plus, they are only a keystroke away (ALT F8) whenever you need them!

Need a primer to Microsoft Office macros? Read this interesting 101 piece from PC World first: http://snipurl.com/macros.

This entry was posted in Miscellaneous and tagged . Bookmark the permalink.

59 Responses to Deleting all hyperlinks from a Microsoft Office document

  1. scanbix says:

    Thank you. Great!
    ping back in Lithuanian from http://www.karalius.wordpress.com

  2. Thanks for this.

    I have been struggling with this problem for a couple years because it slows down my computer when I load and/or scroll through documents.

    For all of y’all with macs, it works on it too…

  3. Paul says:

    Thank you so much. I’ve been trying to figure this out for *ages*!
    *Very* much appreciated.

  4. Angelique says:

    OMG! I actually did a happy dance. Thank you so much. This was extraordinarily helpful.

  5. James says:

    both worked fine for me :D Thanks both of you

  6. A.Walker says:

    Brilliant, I’ve never used macro before but the instructions were v. easy to follow and it took a second to work. Thought I’d spend the time I will now be saving to write a thank you!

  7. Renuka says:

    Wonderful, thanks a lot. great help

  8. Trevor says:

    Hi,

    I am using MS Word 2007… I followed your steps by adding the module in MS Visual Basic and then applied to document. However, I want to disable it as I need to have hyperlinks in some of my documents. But now whenever I copy text over that has a hyperlink, it gets rid of the hyperlink and makes it turn into the actual link web address. It is doing that in all of my Word documents that I create now. So basically, how do I go about deleting/disabling this feature permanently?

    Please let me know as soon as possible.

    Thanks!

  9. Melissa says:

    I like this macro – but I want to do something further – I want to copy the URL from the HYPERLINK field, then remove the hyperlink so that I end up with some thing like this:

    Mom’s Diner
    http://www.momsdiner.com
    ADDRESS
    CITY, STATE ZIP

    I need the URL information, but I want it displayed independently of the hyperlinked text.

    Any thoughts? It’s taking me a HUGE amount of time to sort this out on my own.

    Thanks in advance!

    Melissa

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>