删除文本而不丢失原始邮件outlook vba的格式

时间:2016-05-30 10:48:06

标签: vba outlook macros

我需要在转发邮件之前删除一些文本,每次执行此操作时都会丢失格式。请参阅下面的代码。

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

如何保持格式化并删除文本?

1 个答案:

答案 0 :(得分:1)

您正在使用纯文本Body属性。您需要阅读并设置HTMLBody属性。