If you want to insert hyperlinks for all occurrences of a specific word in the current Outlook email body, you can utilize the method exposed in this article. It is using VBA to quickly achieve it.
In my previous article – “Why Not Use AutoCorrect to Insert Specific Hyperlinks”, you can utilize AutoCorrect to insert hyperlinks. By that means, Outlook will auto add hyperlink to the specific words when you type. However, it demands that you have already set the words and hyperlinks in “AutoCorrect Options” before typing. But, most of time, what you want is to quickly insert hyperlinks for all occurrences of a specific word after you compose an email. In this case, AutoCorrect cannot help. Therefore, you must long for a means to achieve this in quick time. Now, in the followings, we’ll teach you how to use VBA to get it.
Batch Insert Hyperlinks for All Occurrences of a Specific Word
- At the very outset, launch your Outlook application.
- Then in the main Outlook window, switch to “Developer” tab and hit “Visual Basic” button or just press “Alt + F11” key shortcuts.
- Next in the new popup window, open a new module that is not in use.
- Subsequently, copy and paste the following VBA codes into this module.
Sub InsertHyperlinkstoOccurrencesSpecificWord () Dim objCurrentMail As Outlook.MailItem Dim objWordDocument As Word.Document Dim objSearchRange As Word.Range Dim strSpecificWord As String Dim strHyperlinkAddress As String Set objCurrentMail = Outlook.Application.ActiveExplorer.Selection.Item(1) Set objWordDocument = objCurrentMail.GetInspector.WordEditor Set objWordApp = objWordDocument.Application Set objSearchRange = objWordDocument.Range 'Input the specific words & hyperlink addresses strSpecificWord = InputBox("Enter the specific words that you want to insert hyperlink to:", "Specify Words") strHyperlinkAddress = InputBox("Input the specific hyperlink address to be inserted:", "Specify Hyperlink Address") 'Insert the hyperlink to all the found specific words While objSearchRange.Find.Execute(FindText:=strSpecificText, MatchWholeWord:=True, Forward:=True) = True objWordDocument.Hyperlinks.Add Anchor:=objSearchRange, Address:=strHyperlinkAddress objSearchRange.Collapse Direction:=wdCollapseEnd Wend End Sub
- After that, you can proceed to add the new macro to Quick Access Toolbar of message window.
- Later verify if your Outlook allows macro running.
- Eventually, you can have a try.
- Firstly, compose an email as usual.
- Then click the new macro button in Quick Access Toolbar.
- Next you’ll be required to input the specific words and specific hyperlink address, like the following screenshot:
- After that, hit “OK”.
- At once, the specified hyperlinks will be inserted to all the occurrences of a specific word, like the image below:
Safeguard Your Outlook Data
Since Outlook is prone to corruption, you should spend a lot of efforts protecting your Outlook data. Although Outlook comes packed with a built-in repair tool, it can’t solve serious problems. Therefore, you had better keep a more potent tool in vicinity, like DataNumen Outlook Repair, which can repair Outlook file without breaking a sweat.
Shirley Zhang is a data recovery expert in DataNumen, Inc., which is the world leader in data recovery technologies, including recover mdf and outlook repair software products. For more information visit www.datanumen.com