将Word文档的内容插入电子邮件并使用VBA包括默认签名

时间:2018-09-18 16:32:12

标签: vba outlook word-vba outlook-vba

我使用了How to send a Word document as body of an email with VBA中Patrick Wynne提供的代码,但是它覆盖了签名。粘贴word文档的内容时,是否可以更改代码以保留默认签名?

代码如下:

Sub emailFromDoc()
    Dim wd As Object, editor As Object
    Dim doc As Object
    Dim oMail As MailItem

    Set wd = CreateObject("Word.Application")
    Set doc = wd.documents.Open(...path to your doc...)
    doc.Content.Copy
    doc.Close
    set wd = Nothing

    Set oMail = Application.CreateItem(olMailItem)
    With oMail
        .BodyFormat = olFormatRichText
        Set editor = .GetInspector.WordEditor
        editor.Content.Paste
        .Display
    End With
End Sub

1 个答案:

答案 0 :(得分:0)

您可以使用:

Sub emailFromDoc()
    Dim wd As Object, editor As Object
    Dim doc As Object
    Dim Rng As Object
    Dim oMail As MailItem

    Set wd = CreateObject("Word.Application")
    Set doc = wd.documents.Open(...path to your doc...)
    doc.Content.Copy
    doc.Close
    Set wd = Nothing

    Set oMail = Application.CreateItem(olMailItem)
    With oMail
        .BodyFormat = olFormatRichText
        Set editor = .GetInspector.WordEditor
        Set Rng = editor.Content
        Rng.Collapse 1
        Rng.Paste
        .Display
    End With
End Sub