PDA

View Full Version : Solved: Change colour of words in message



Sir Babydum GBE
07-11-2007, 03:54 AM
Hi

I've been playing with the rules on Outlook - and I note that I can get a rule to "run a script" if certain conditions are met.

So, what I'm hoping for is this:

If my name is mentioned in the body text of an email, then I want all occurrences of my name to be turned red and bold.

Is this possible?

Thanks

BD

mvidas
07-11-2007, 05:56 AM
Sir BD,

Give the following a try:Sub RedAndBoldTheName(vMsg As MailItem)
vName = "Babydum"
If vMsg.BodyFormat = olFormatHTML Then
If InStr(1, vMsg.HTMLBody, vName, vbTextCompare) > 0 Then
vMsg.HTMLBody = Replace(vMsg.HTMLBody, vName, _
"<font color=""red""><b>" & vName & "</b></font>")
vMsg.Save
End If
End If
End SubEDIT: big change from the notif email

Sir Babydum GBE
07-11-2007, 06:31 AM
Thanks Matt

It works in the preview window - and when I open the currently previewed message. But the minute I click on a different message, all the formatting goes, even when I go back to the one I saw had the new formatting.

BD

mvidas
07-11-2007, 06:46 AM
Hmm.... as I don't have outlook 2003 installed I can't test it with the "Run as script" or with BodyFormat, but I just tested it using:Sub BDTest()
Dim MailItm As Object
If ActiveInspector Is Nothing Then 'if message not opened up full screen
Set MailItm = ActiveExplorer.Selection.Item(1)
Else
Set MailItm = ActiveInspector.CurrentItem
End If
RedAndBoldTheName MailItm
End Sub
Sub RedAndBoldTheName(vMsg As MailItem)
vName = "Babydum"
If Len(vMsg.HTMLBody) > 0 Then 'If vMsg.BodyFormat = olFormatHTML Then
If InStr(1, vMsg.HTMLBody, vName, vbTextCompare) > 0 Then
vMsg.HTMLBody = Replace(vMsg.HTMLBody, vName, _
"<font color=""red""><b>" & vName & "</b></font>")
vMsg.Save
End If
End If
End SubThis only works on an active item, so the updating doesnt work until I change to another message and then click back. Even switching to another folder (I checked Sent to verify that didnt change, which it didnt) and then back again didn't affect the new red/bold Babydum name...?