How to Remove All Hyperlinks in a Word Document Using VBA
[ad_1]
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.
How to Automatically Remove All Hyperlinks in a Word Document Using VBA
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:
- Go to the File menu in Word.
- Select Options. This will open the Word Options window.
- In Word Options, select Customize Ribbon from the tabs on the left.
- On the right, under Main Tabs, check Developer.
- 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.
- Go to the Developer tab.
- From the Code section, select Macros. This will open the Macros window.
- Enter a name for your macro in the text box.
- 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:
Selection.WholeStory
Selection.Fields.Unlink
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.
- Go to the Files menu in Word.
- Click on Options at the bottom of the list.
- In Word Options, go to Customize Ribbon.
- Click on Customize next to Keyboard shortcuts. This will open a new window.
- In the new window, scroll down the Categories list and select Macros.
- On the right, under Macros, select your macro.
- Click the text box under, Press new shortcut key.
- 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.
- 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.
[ad_2]
Source link