?
Solved

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

Posted on 2009-07-13
1
Medium Priority
?
1,863 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

[Webinar] How Hackers Steal Your Credentials

Do You Know How Hackers Steal Your Credentials? Join us and Skyport Systems to learn how hackers steal your credentials and why Active Directory must be secure to stop them.

Question has a verified solution.

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

In this step by step procedure, you will come to know the details of creating an Outlook meeting in 2007, 2010, 2013 & 2016.
Changing a few Outlook Options can help keep you organized!
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …
There are cases when e.g. an IT administrator wants to have full access and view into selected mailboxes on Exchange server, directly from his own email account in Outlook or Outlook Web Access. This proves useful when for example administrator want…
Suggested Courses

764 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