How to remove all hyperlinks in a Word document using VBA

Deleting hyperlinks in Word is easier than even adding them, but this child’s play can become quite tiring when done in large quantities. VBA is a powerful tool in Office applications, including Word, that allows you to automate almost any task.

By using VBA to create a macro in Word, you can remove all hyperlinks from your document in one quick motion. This way you can increase your speed when it comes to removing hyperlinks from dozens of documents.

VBA or Visual Basic for Applications allows you to write snippets of code as macros in Word. Each time you run the macro, the Visual Basic code runs, automatically completing the task assigned to it.

Removing hyperlinks in Word using VBA requires little knowledge of the programming language itself, as it all boils down to two lines, but it will help ease your workload. To create this simple macro, we will go to the developer tab, create the macro, insert the corresponding code, and then use it.

These steps are exclusive to the first time you create the macro. Then all you have to do is press the hotkey to run the code and remove the hyperlinks. If you’re looking for a head start on Word macros, read our article on how to get started using macros in Word.

1. Access the Developer tab

The first step is to go to the Developer tab in Word. For security reasons, this tab and its features are disabled by default in Word. Here’s how to access the Developer tab in Word:

  1. Go to the Case menu in Word.
  2. Select Choice. This will open the Word Options the window.
  3. In Word Options, select Customize the Ribbon in the left tabs.
  4. On the right, under Main tabsCheck Developer.
  5. Click on OKAY.

Now the Developer tab will appear between the View and Help tabs.

2. Creation of the macro

With the Developer tab available, now is the time to create a macro and write some code for it.

  1. Go to the Developer tongue.
  2. From Coded section, select Macros. This will open the Macros window.
  3. Enter a name for your macro in the text box.
  4. Click on Create.

Once you have clicked Create, you will be taken to the VBA workspace, where you can see your macro code. Right now, your code should consist of two declarations:

A Under at the start to indicate the start of your macro, and a End caption at the end to indicate the end of your macro. The green line is a comment that does not affect the code. It’s there to save you from getting lost when you have dozens of macros.

Now it’s time to add the code. Copy the code below and paste it just before the End caption statement:


The code here is simple. First, we select the entire document with Selection.WholeStory. Once the whole document is selected, Selection.Fields.Ungroup will run to ungroup all fields from the text. This way, the hyperlinks are unlinked, but their anchor texts or graphics remain as they were. Your code should look like the following:

3. Using the macro

Once you are done with your code, simply close the VBA workspace. You don’t need to save or anything like that. The next step now is to create a shortcut for this macro to make removing hyperlinks even easier.

  1. Go to the Files menu in Word.
  2. Click on Choice at the bottom of the list.
  3. In Word Options, navigate to Customize the ribbon.
  4. Click on Personalize close to Keyboard shortcuts. This will open a new window.
  5. In the new window, scroll the Categories list and select Macros.
  6. On the right, under Macrosselect your macro.
  7. Click on the text box under, Press the new shortcut key.
  8. Enter a key combination as a shortcut for your macro. It is better to include Gap, CTRLand Other in your combination so that it doesn’t interfere with the default Word shortcuts.
  9. Click on close then click OKAY.

Your macro is now usable with the keyboard shortcut you just assigned to it. Go ahead and press the key combination on your keyboard. The macro will do its magic!

Automate your tasks with VBA in Word

VBA is a useful tool designed to relieve you when you need to make changes to dozens of documents. Deleting hyperlinks in Word is easy in a single document, but it can get tricky when you have to do it multiple times afterwards. Now you know how to automate this task and let your macro take care of it.

The beauty of VBA doesn’t end with simple macros. This could be the first step on your journey to mastering VBA and creating great macros and functionality in Word and other Office applications.

Comments are closed.