How to Remove All Hyperlinks in a Word Document Using VBA


Removing hyperlinks in Word is easier than even adding them, but this cinch can get rather tiring when done in great quantities. VBA is a powerful tool in Office apps, including Word, that allows you to automate nearly any task.

By using VBA to create a macro in Word, you can have all the hyperlinks in your document removed in one swift motion. This way, you can boost your speed when it comes to removing hyperlinks from dozens of documents.

VBA or Visual Basic for Applications allows you to write pieces of code in the form of macros in Word. Whenever you run the macro, the Visual Basic code will run, automatically completing the task assigned to it.

Removing hyperlinks in Word using VBA requires little knowledge of the programming language itself, as it is all summed up in two lines, but it will help take some weight off your workload. To create this simple macro, we’re going to access the developer tab, create the macro, insert the code for it, and then use it.

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

1. Accessing the Developer Tab

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

  1. Go to the File menu in Word.
  2. Select Options. This will open the Word Options window.
  3. In Word Options, select Customize Ribbon from the tabs on the left.
  4. On the right, under Main Tabs, check Developer.
  5. Click OK.

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

2. Creating the Macro

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

  1. Go to the Developer tab.
  2. From the Code 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 click Create, you’ll be taken to the VBA workspace, where you can see the code for your macro. Right now, your code should be made up of two statements:

A Sub statement at the beginning to indicate the start of your macro, and an End Sub statement at the end to indicate the end of your macro. The green line is a comment which doesn’t affect the code. It’s there to prevent you from getting confused when you have dozens of macros.

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


The code here is a simple one. First, we select the entire document with Selection.WholeStory. Once the entire document is selected, Selection.Fields.Unlink will run to unlink any fields in the text. This way, the hyperlinks are unlinked, but their anchor texts or graphics remain as they were. Your code should look like the below:

3. Using the Macro

Once you’re done with your code, simply close the VBA workspace. You don’t need to save or anything of that sort. Now the next step 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 Options at the bottom of the list.
  3. In Word Options, go to Customize Ribbon.
  4. Click on Customize next to Keyboard shortcuts. This will open a new window.
  5. In the new window, scroll down the Categories list and select Macros.
  6. On the right, under Macros, select your macro.
  7. Click the text box under, Press new shortcut key.
  8. Enter a key combination as the shortcut for your macro. It’s best to include Shift, Ctrl, and Alt in your combination so that it doesn’t interfere with the default Word shortcuts.
  9. Click Close and then click OK.

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

Automate Your Tasks With VBA in Word

VBA is a useful tool designed to take some weight off your shoulder when you have to make adjustments to dozens of documents. Removing hyperlinks in Word is easy in a single document, but it can get tough when you have to do it many times consequentially. 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 might be the first step in your journey to mastering VBA and creating wonderful macros and features in Word and other Office apps.


Source link

Leave a Reply

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

Call Us