VBA Macro to highlight some Keyword in mail body?

Status
Not open for further replies.

yjsfox

New Member
Outlook version
Outlook 2016 32 bit
Email Account
Exchange Server
Hi, I have been looking for a method to do keyword (including whole line) highlight (coloring is better) if the incoming mail body matched some rules/expr.

Say, I want to highlight the line "05/12/2017: 2 Hours On Fri; Category: Vacation - SJ" by matching rule: lines with date in start and has "Category:"

Is that doable in outlook VBA macro?
Thanks!!!
(I am using outlook 2016 and outlook 2013)

-- mail body--
..
Time Off Request Details:
05/12/2017: 2 Hours On Fri; Category: Vacation - SJ

Time Off Plan Balances as of 05/12/2017:
...
----mail body--
 

Diane Poremsky

Senior Member
Outlook version
Outlook 2016 32 bit
Email Account
Office 365 Exchange
you can use regex to match, but you would need to rewrite the html to highlight it. Adding the category is no problem. If the line has special formatting already, it would probably be easier to do (since the html formatting already exists, just need to add to the style.)
 

Diane Poremsky

Senior Member
Outlook version
Outlook 2016 32 bit
Email Account
Office 365 Exchange
Actually... the simple script in this url works - as long as that line has unique formatting you can look for and replace.
How to Change the Font used for Outlook's RSS Feeds

(ETA: i just tested it - works fine - just make sure you use the right value for oldfont. I should change the order of the strings so oldfont is entered first, then new. :))
 
Last edited:

yjsfox

New Member
Outlook version
Outlook 2016 32 bit
Email Account
Exchange Server
Hi, Thanks for the hint. Sorry that I didn't try it until these days.
I am not very familiar with the regex. That's what need help for.

My purpose is to highlight the name and date/time in the Mailbody so it will look like this:
(Note the name and date/time has been bold faced to make it easier to read)

You have a new Workday business process pending approval for John Smith. You can now process this request via email reply or by logging into Workday to approve or reject this request.
Time Off Request Details:
08/25/2017: 8 Hours On Fri; Category: Floating Holiday - SJ
The bold face is not fixed so I definitely need regex to match the strings Ineed (name and date/time).
I have managed to do it using the following code. "nearly right" but need to refine the target string (wordToSearch) to be a regex extracted string.
The folloiwng code only get the "business process pending approval for" highlighted


Sub HighlightString (MyMail As Outlook.MailItem)
Dim strID As String
Dim objMail As Outlook.MailItem
strID = MyMail.EntryID
Set objMail = Application.Session.GetItemFromID(strID)
wordToSearch = "business process pending approval for "
' Ineed to find a way to match keyword from this line, assigned to wordToSearch

If InStr(1, objMail.HTMLBody, wordToSearch, vbTextCompare) > 0 Then
strData = objMail.HTMLBody
strData = Replace(strData, wordToSearch, "<FONT style=" & Chr(34) & "BACKGROUND-COLOR: yellow" & Chr(34) & ">" & wordToSearch & "</FONT>")
objMail.HTMLBody = strData
objMail.Save
End If
Set objMail = Nothing
End Sub
Thanks much for the help in advance!
 
Status
Not open for further replies.
Thread starter Similar threads Forum Replies Date
A VBA macro for 15 second loop in send and received just for 1 specific mailbox Outlook VBA and Custom Forms 1
G VBA Macro Calendar Printing Assistant 3
R Help Revising VBA macro to delete email over different time span Outlook VBA and Custom Forms 0
L Moving emails with similar subject and find the timings between the emails using outlook VBA macro Outlook VBA and Custom Forms 1
N How can I increase/faster outlook VBA Macro Speed ? Using Outlook 2
D.Moore Folder view settings by VBA macro Outlook VBA and Custom Forms 57
J Help Please!!! Outlook 2016 - VBA Macro for replying with attachment in meeting invite Outlook VBA and Custom Forms 9
R VBA macro - new message Outlook VBA and Custom Forms 3
S Example VBA Macro - To Conditionally Change the From Account and Add a BCC Address on Emails Outlook VBA and Custom Forms 11
S VBA Macro - Run-time error '424': object required - Help Please Outlook VBA and Custom Forms 3
B VBA Macro for assigning multiple Categories to an email in my Inbox Outlook VBA and Custom Forms 1
M Slow VBA macro in Outlook Outlook VBA and Custom Forms 5
M VBA macro for Inbox's attachments search Outlook VBA and Custom Forms 0
J Macro only runs within VBA Editor Outlook VBA and Custom Forms 2
D VBA macro printing attachments in shared mailbox Outlook VBA and Custom Forms 1
G VBA/Macro to remove page colour when replying or forwarding email Outlook VBA and Custom Forms 2
S Outlook 7 VBA macro for multiple filing Outlook VBA and Custom Forms 1
M Outlook VBA Macro that could retrieve/display the (From, Subject, Date Received) Outlook VBA and Custom Forms 2
Philip Rose Recreating a WORD Editing Macro to use in Outlook VBA Outlook VBA and Custom Forms 4
T Random problem in VBA macro Outlook VBA and Custom Forms 6
M recover deleted items vba macro Outlook VBA and Custom Forms 2
P Vba script including macro appears in rules but wont run Outlook VBA and Custom Forms 6
S VBA Macro to VBScript Outlook VBA and Custom Forms 1
L VBA Macro to flag sent emails Using Outlook 1
B Outlook vba macro Using Outlook 1
B Auto BCC VBA macro: how to add exceptions? Using Outlook 28
R VBA Macro to VBScript in a form- Help Please! Using Outlook 10
D VBA Macro Works in 2007 but errors in 2010 Using Outlook 2
P VBA Macro for formatting multiple phone numbers in outlook contacts Using Outlook 1
C Outlook VBA - Create Macro Move Contact field Item to Another Using Outlook 1
E Word macro running from OL VBA throwing error on Word SaveAs?? Outlook VBA and Custom Forms 8
J Outlook custom form - VBS call VBA macro Outlook VBA and Custom Forms 3
N VBA Procedure (or Macro) to Stop Outlook from Closing? Outlook VBA and Custom Forms 2
M Run external program from Outlook VBA macro Outlook VBA and Custom Forms 5
D New Macro / VBA Outlook VBA and Custom Forms 7
J Specify Font Name or Face using VBA Macro in Word Outlook VBA and Custom Forms 2
S Custom VBA forms in Outlook--how to call w/macro? Outlook VBA and Custom Forms 1
S macro ist just worling wenn vba editor is open! Outlook VBA and Custom Forms 1
D.Moore VBA script fail after Office 365 update Using Outlook 8
R Limiting length of saved attachment in VBA Outlook VBA and Custom Forms 2
S Skype for business meeting vba code Outlook VBA and Custom Forms 1
C How to use VBA to show only items x days old or more Outlook VBA and Custom Forms 1
B VBA to convert email to task, insert text of email in task notes, and attach copy of original email Outlook VBA and Custom Forms 4
D Outlook VBA error extracting property data from GetRules collection Outlook VBA and Custom Forms 10
S Reference Custom Fields with VBA Outlook VBA and Custom Forms 2
PGSystemTester VBA To Change AppointmentItem.BusyStatus From MeetingItem Before Send Using Outlook 0
O Email not leaving Outbox when using Excel VBA to sync Outlook account Outlook VBA and Custom Forms 4
B VBA to Collapse Task Folder Groups Outlook VBA and Custom Forms 1
R Expand VBA Permanent Delete Code Outlook VBA and Custom Forms 6
shrydvd vba to secure zip attachments Outlook VBA and Custom Forms 3
Similar threads


















































Top