Skip to main content

Kutools for Office β€” One Suite. Five Tools. Get More Done.

How to automatically highlight specific keywords from incoming emails in Outlook

Author Sun Last modified

In Outlook, you may receive hundreds and thousands emails every day, have you ever wanted to auto highlight some specific keywords from incoming emails? In this article, I introduce a VBA code to automatically highlight the keywords you specify from incoming emails in Outlook.

Auto highlight keywords from incoming emails


Auto highlight keywords from incoming emails

No built-in function in outlook can handle this job except VBA.

1. Press Alt + F11 key to enable the Microsoft Visual Basic for Applications window.

2. Then double click ThisOutlookSession in left Project pane, and copy and paste below code to the new code window.

VBA: Auto highlight keywords in incoming emails

Public WithEvents GMailItems As Outlook.Items
'UpdatebyExtendoffice20181106
Private Sub Application_Startup()
    Set GMailItems = Outlook.Application.Session.GetDefaultFolder(olFolderInbox).Items
End Sub
Private Sub GMailItems_ItemAdd(ByVal Item As Object)
    If Item.Class <> olMail Then Exit Sub
    AutoHighlight_SpecificWords Item
End Sub
Sub AutoHighlight_SpecificWords(Mail As Outlook.MailItem)
    Dim xWord As Variant
    Dim xHTMLBody As String, xStr As String
    Dim xWordArr
    On Error Resume Next
    xWordArr = Array("Kutools", "Important")  'keyword
    xHTMLBody = Mail.HTMLBody
    For Each xWord In xWordArr
        If InStr(xHTMLBody, xWord) > 0 Then
            xStr = "<font style=" & Chr(34) & "background-color: yellow" & Chr(34) & ">" & xWord & "</font>"
            xHTMLBody = Replace(xHTMLBody, xWord, xStr)
            Mail.HTMLBody = xHTMLBody
        End If
    Next
    Mail.Save
End Sub

 

Tip: in the code, you can change the keywords as you need in this script xWordArr = Array("Kutools", "Important") .

3. Then save the code and go back to Outlook,under Home tab, click Rules > Manage Rules & Alerts.
doc auto highlight text 1

4. In the Rules and Alerts dialog, click New Rule under E-mail Rules tab, then in Rules Wizard dialog, click Apply rule on messages I receive.
doc auto highlight text 2

5. Click Next > Next > Yes to go to the third dialog, check run a script from Step1 section, then click a script in Step2 section to enable Select Script dialog, choose this code Project1.ThisOutlookSession.AutoHighlight_SpecificWords. Click OK.
doc auto highlight text 3 doc auto highlight text 4

6. Click Next > Next, in last dialog, give a name for this rule.
doc auto highlight text 5

7. Click Finish > OK to finish the rule.

From now on, the keywords you specified will be auto highlighted in the incoming emails.
doc auto highlight text 6


Save or Export Multiple emails to other fomat files(PDF/HTML/WORD/EXCEL) in Outlook

Sometimes, you may want to save or export the emails to a folder as other format files, such as PDF, Word or Excel files in Outlook. In Outlook, neither of the Save as and Export function can handle this job. However, Kutools for Outlook's Save as file utility can export multiple emails to a folder as files with multiple formats at once time.    Click for 45 days free trial!
doc save as file
 
Kutools for Outlook: with dozens of handy Outlook add-ins, free to try with no limitation in 45 days.

Best Office Productivity Tools

Breaking News: Kutools for Outlook Launches Free Version!

Experience the all-new Kutools for Outlook with 100+ incredible features! Click to download now!

πŸ€– Kutools AI : Uses advanced AI technology to handle emails effortlessly, including replying, summarizing, optimizing, extending, translating, and composing emails.

πŸ“§ Email Automation: Auto Reply (Available for POP and IMAP)  /  Schedule Send Emails  /  Auto CC/BCC by Rules When Sending Email  /  Auto Forward (Advanced Rules)   /  Auto Add Greeting   /  Automatically Split Multi-Recipient Emails into Individual Messages ...

πŸ“¨ Email Management: Recall Emails  /  Block Scam Emails by Subjects and Others  /  Delete Duplicate Emails  /  Advanced Search  /  Consolidate Folders ...

πŸ“ Attachments ProBatch Save  /  Batch Detach  /  Batch Compress  /  Auto Save   /  Auto Detach  /  Auto Compress ...

🌟 Interface Magic: 😊More Pretty and Cool Emojis   /  Remind you when important emails come  /  Minimize Outlook Instead of Closing ...

πŸ‘ One-click Wonders: Reply All with Attachments  /   Anti-Phishing Emails  /  πŸ•˜Show Sender's Time Zone ...

πŸ‘©πŸΌβ€πŸ€β€πŸ‘©πŸ» Contacts & Calendar: Batch Add Contacts From Selected Emails  /  Split a Contact Group to Individual Groups  /  Remove Birthday Reminders ...

Use Kutools in your preferred language – supports English, Spanish, German, French, Chinese, and 40+ others!

Instantly unlock Kutools for Outlook with a single click. Don't wait, download now and boost your efficiency!

kutools for outlook features1 kutools for outlook features2

πŸš€ One-Click Download β€” Get All Office Add-ins

Strongly Recommended: Kutools for Office (5-in-1)

One click to download five installers at once β€” Kutools for Excel, Outlook, Word, PowerPoint and Office Tab Pro. Click to download now!

  • βœ… One-click convenience: Download all five setup packages in a single action.
  • πŸš€ Ready for any Office task: Install the add-ins you need, when you need them.
  • 🧰 Included: Kutools for Excel / Kutools for Outlook / Kutools for Word / Office Tab Pro / Kutools for PowerPoint