如何删除回复消息中HTML正文签名上方自动生成的行?

问题描述 投票:0回答:1

我尝试了删除签名上方自动生成的行的解决方案,如果我创建一个项目,它效果很好

Sub sig_and_email_send()
    Dim OutApp As Object
    Dim OutMail As Object
    Dim signature As String

    With Application
        .EnableEvents = False
        .ScreenUpdating = False
    End With

    Set OutApp = CreateObject("Outlook.Application")
    Set OutMail = OutApp.CreateItem(0)

  'gets default signature from e-mail
    With OutMail
        '2 = HTMLBody Format
        .BodyFormat = 2
        .Display
        'deletes blank space present before signature
        signature = Replace(OutMail.HTMLBody, "<p class=MsoNormal><o:p>&nbsp;</o:p></p>", "")
        'removes entire e-mail contents and then closes with discard
        OutMail.HTMLBody = Replace(OutMail.HTMLBody, OutMail.HTMLBody, "")
        OutMail.Close 1
    End With
    
    On Error Resume Next
    With OutMail
        .to = "[email protected]"
        .CC = "[email protected]"
        .BCC = "[email protected]"
        .Subject = "Subject"
        .Attachments.Add "\\network\folder\documents\file.xlsx"
        .HTMLBody = .HTMLBody & "Hi," & "whateveryourtextis" & _
        "<br>" & "Thanks," & "<br><br>" & signature
        .Display 'or use .Send
    End With
    On Error GoTo 0

    With Application
        .EnableEvents = True
        .ScreenUpdating = True
    End With

    Set OutMail = Nothing
    Set OutApp = Nothing
End Sub

我的帮助请求是如何在回复电子邮件时应用该解决方案,它似乎无法运行。

我喜欢我,自动生成的行将从 Outlook 中的回复邮件中删除

vba outlook
1个回答
0
投票

在 Outlook 中编码。

首先打开一个邮件项目。

Option Explicit

Sub modify_reply()

Dim origItem As Object
Dim repMail As MailItem
Dim editedSignatureAndOrigHTMLBody As String

Set origItem = ActiveInspector.currentItem
If TypeName(origItem) <> "MailItem" Then Exit Sub
Set repMail = origItem.Reply
origItem.Close olDiscard

With repMail
    '2 = HTMLBody Format
    .BodyFormat = 2
    
    'Debug.Print .htmlbody
    Debug.Print "Len(.htmlbody): " & Len(.htmlbody)
    
    ' generate signature
    .Display
    
    'Debug.Print .htmlbody
    Debug.Print "Len(.htmlbody): " & Len(.htmlbody)
        
    ' delete blank space present before signature
    '  deleting <p class=MsoNormal><o:p>&nbsp;</o:p></p> had no impact in my test
    editedSignatureAndOrigHTMLBody = Replace(.htmlbody, "<p class=MsoNormal><o:p>&nbsp;</o:p></p>", "")
    'Debug.Print editedSignatureAndOrigHTMLBody
    Debug.Print "Len(editedSignatureAndOrigHTMLBody): " & Len(editedSignatureAndOrigHTMLBody)
    
    .htmlbody = "Hi," & "whateveryourtextis" & _
      "<br>" & "Thanks," & "<br><br>" & editedSignatureAndOrigHTMLBody
     
End With

End Sub
© www.soinside.com 2019 - 2024. All rights reserved.