Word

Remove all Hyperlinks

Ease of Use

Easy

Version tested with

2002 

Submitted by:

Justinlabenne

Description:

Hard codes all hyperlinks in the current document to the displayed text 

Discussion:

You can remove hyperlinks by deleting the style called Hyperlink, or by hitting Ctrl+A, then Shift+Ctrl+F9 (which will remove all underlying fields), but if you have alot of documents that contain hyperlinks, this code speeds up Word's native function. A quicker way to do it if there are lots of hyperlinks per document, or you're using it as part of another procedure. There is a code for just the current document, and a code taht will remove hyperlinks from "all" open documents. 

Code:

instructions for use

			

Option Explicit Sub KillTheHyperlinks() ' ----------------------------------------------- ' Removes all hyperlinks from the document: ' Text to display is left intact ' ----------------------------------------------- With ThisDocument ' Loop while there are hyperlinks afoot! While .Hyperlinks.Count > 0 .Hyperlinks(1).Delete Wend End With ' Shut this off, don't need anymore popping up Application.Options.AutoFormatAsYouTypeReplaceHyperlinks = False End Sub Sub KillTheHyperlinksInAllOpenDocuments() ' ----------------------------------------------- ' Removes all hyperlinks from any open documents ' Text to display is left intact ' ----------------------------------------------- Dim doc As Document Dim szOpenDocName As String ' Loop through all open documents: For Each doc In Application.Documents ' Store the document name szOpenDocName = doc.Name ' Remove the hyperlinks from that document With Documents(szOpenDocName) ' Loop while there are hyperlinks afoot! While .Hyperlinks.Count > 0 .Hyperlinks(1).Delete Wend End With ' Shut this off, don't need anymore popping up Application.Options.AutoFormatAsYouTypeReplaceHyperlinks = False Next doc End Sub

How to use:

  1. Open your Word document
  2. Press Alt + F11 to open VBE
  3. Insert-Module. (Insert -> module)
  4. Paste the code there in the window at right. (F7)
  5. Close VBE (Alt + Q or press the X in the top right hand corner)
  6. Save the file
 

Test the code:

  1. Press Alt + F8 to open the macro dialog box
  2. Select KillTheHyperlinks
  3. Click Run
 

Sample File:

RemovesHyperlinks.zip 6.81KB 

Approved by mdmackillop


This entry has been viewed 148 times.

Please read our Legal Information and Privacy Policy
Copyright @2004 - 2020 VBA Express