View Single Post
 
Old 07-09-2014, 02:05 PM
niton niton is offline Windows 7 64bit Office 2010 64bit
Competent Performer
 
Join Date: Jul 2012
Posts: 102
niton is on a distinguished road
Default

Add the loop from the Word code to the Outlook code.

Code:
 
Sub SearchMailMessageHighlight()
Dim objMail As Outlook.mailItem
 
Dim wordToSearch As String
Dim strData As String
 
Dim i As Long
Dim StrFnd As String
StrFnd = "display,e/monitor,e/port,mouse,keyboard,case,wide,screen,monitor,e-port"
 
' Must have an open message
Set objMail = Application.ActiveInspector.currentItem
 
objMail.Display ' In case it is behind something or minimized
 
For i = 0 To UBound(Split(StrFnd, ","))
    wordToSearch = Split(StrFnd, ",")(i)
 
    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
 
       'To reverse highlighting when testing
        'strData = Replace(strData, wordToSearch, "<FONT style=" & Chr(34) & "BACKGROUND-COLOR: white" & Chr(34) & ">" & wordToSearch & "</FONT>")
        'objMail.HTMLBody = strData
 
        'objMail.save
 
    End If
 
Next
Set objMail = Nothing
End Sub

Last edited by niton; 07-09-2014 at 02:08 PM. Reason: formatting the code
Reply With Quote