![]() |
|
#2
|
|||
|
|||
|
From http://www.outlookcode.com/threads.a...essageid=33313
For the original you have to pass a mailitem Code:
Sub CustomMailMessageRule(myMail As Outlook.mailItem) Dim strID As String Dim objMail As Outlook.mailItem Dim wordToSearch As String Dim strData As String strID = myMail.EntryID Set objMail = Application.Session.GetItemFromID(strID) wordToSearch = "the" 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 Code:
Sub SearchMailMessageHighlight()
Dim strID As String
Dim objMail As Outlook.mailItem
Dim wordToSearch As String
Dim strData As String
' Must have an open message
Set objMail = Application.ActiveInspector.currentItem
objMail.Display ' In case it is behind something or minimized
wordToSearch = InputBox(Prompt:="Enter search string.", Title:="SearchMailMessage", Default:="the")
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
Set objMail = Nothing
End Sub
|
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
Find and highlight multiple words in MS Word document
|
AtaLoss | Word VBA | 37 | 09-22-2021 12:04 PM |
VBA to highlight words if used too much
|
aolszewski | Word VBA | 3 | 11-23-2013 02:07 AM |
| permanently highlight searched words in word 2013 | arjay | Word | 4 | 08-16-2013 09:29 AM |
Highlight all underlined words
|
zdodson | Word VBA | 1 | 07-11-2013 04:53 PM |
Macro to highlight words
|
bertietheblue | Word VBA | 9 | 07-01-2013 12:39 PM |