Solved

How do I highlight text in a message body with VBA?

Posted on 2009-07-13
1
1,697 Views
Last Modified: 2013-11-05
Hello,

My task is to compare the bodies of two messages using VBA and highlight the text of the second message where the values are different. I am using the following code to split the lines of the message bodies into string arrays using the Split function and then loop through the lines and compare them. I am attempting to enclose each line with <div> tags and apply a style to change the text color. I later set the BodyFormat property to olFormatHTML when I send the final message but the resultant markup is displayed in the message. Is there another possible solution to this problem?
Dim beginRedDiv As String, beginBlackDiv As String, endDiv As String

    beginRedDiv = "<div style='color:red;'>"

    beginBlackDiv = "<div style='color:black;'>"

    endDiv = "</div>"

    

    Dim oldUpdateMessageBody() As String, newUpdateMessageBody As String, newTranscriptionMessageBody() As String

    

    oldUpdateMessageBody = Split(OriginalMessage.Body, vbCrLf)

    newTranscriptionMessageBody = Split(mUpdateMatchMessage.Body, vbCrLf)

    

    Dim i As Integer

    For i = 0 To UBound(oldUpdateMessageBody)

        If oldUpdateMessageBody(i) <> newTranscriptionMessageBody(i) Then

            newUpdateMessageBody = newUpdateMessageBody & beginRedDiv & oldUpdateMessageBody(i) & endDiv

        Else

            newUpdateMessageBody = newUpdateMessageBody & beginBlackDiv & oldUpdateMessageBody(i) & endDiv

        End If

    Next

Open in new window

0
Comment
Question by:Curto123
1 Comment
 

Accepted Solution

by:
Curto123 earned 0 total points
ID: 24843935
I seem to have found the solution on my own. I just needed to dig a little more. It seems all I needed to was use the HTMLBody property of the final message instead of the Body property. My text is now colored appropriately.
0

Featured Post

Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Rename the Clutter folder in Office365 3 78
outlook office 365 8 76
exchange, outlook 8 54
exchange, outlook 2 26
Resolve Outlook connectivity issues after moving mailbox to new Exchange 2016 server
This process describes the steps required to Import and Export data from and to .pst files using Exchange 2010. We can use these steps to export data from a user to a .pst file, import data back to the same or a different user, or even import data t…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
This Experts Exchange video Micro Tutorial shows how to tell Microsoft Office that a word is NOT spelled correctly. Microsoft Office has a built-in, main dictionary that is shared by Office apps, including Excel, Outlook, PowerPoint, and Word. When …

932 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

8 Experts available now in Live!

Get 1:1 Help Now