Rinu
Rinu

Reputation: 354

delete text without losing format of original message outlook vba

I need to delete some text before forwarding a mail, i am losing the formatting each time i do this. please see the code below.

Sub RemoveExpression()

Dim Insp As Inspector
Dim obj As Object
Dim subStr As String
Dim oMail As MailItem
Dim itmOld As MailItem, itmNew As MailItem
    Set Insp = Application.ActiveInspector
    Set oMail = Insp.CurrentItem

    lPosition = InStr(oMail.Body, "Subject: ") - 1
   '   obj.Subject = Mid(oMail.Subject, 5)
    subStr = Left(oMail.Body, lPosition)
    oMail.Body = Replace(oMail.Body, subStr, "")
    oMail.Subject = Replace(oMail.Subject, "FW:", "")

    'obj.Body = Replace(obj.HTMLBody, "abc", "")
    Set obj = Nothing
    Set Insp = Nothing
End Sub

how do i keep the formating and delete the text ?

Upvotes: 0

Views: 522

Answers (1)

Dmitry Streblechenko
Dmitry Streblechenko

Reputation: 66215

You are working with the plain text Body property. You need to read and set the HTMLBody property.

Upvotes: 1

Related Questions