Microsoft Office Forums

Go Back   Microsoft Office Forums > >

 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
  #4  
Old 07-09-2014, 02:05 PM
niton niton is offline Adapt a script used in Word to highlight words, to work in Outlook? Windows 7 64bit Adapt a script used in Word to highlight words, to work in Outlook? 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
 



Similar Threads
Thread Thread Starter Forum Replies Last Post
Adapt a script used in Word to highlight words, to work in Outlook? Find and highlight multiple words in MS Word document AtaLoss Word VBA 37 09-22-2021 12:04 PM
Adapt a script used in Word to highlight words, to work in Outlook? 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
Adapt a script used in Word to highlight words, to work in Outlook? Highlight all underlined words zdodson Word VBA 1 07-11-2013 04:53 PM
Adapt a script used in Word to highlight words, to work in Outlook? Macro to highlight words bertietheblue Word VBA 9 07-01-2013 12:39 PM

Other Forums: Access Forums

All times are GMT -7. The time now is 06:49 PM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2025, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2025 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft