在模板后添加常用签名

时间:2016-08-18 01:54:04

标签: excel vba excel-vba templates outlook

我有这个问题,如果我必须通过Excel VBA在我的Outlook邮件中添加签名,则不包括签名。它仅被模板覆盖。如果您询问我是如何插入模板的,请点击here,这是我之前的问题。我现在的问题是在模板后插入签名。这是我到目前为止所尝试的:

Dim objMail as Object, attach as object, wordDoc as Word.Document
Dim main as Worksheet, rngBody as Range

set main = Thisworkbook.sheets("Main")
    Set objMail = objOutlook.CreateItem(0)
    Set attach = objMail.attachments
    Set wordDoc = objMail.GetInspector.WordEditor

    With main
        Set rngBody = .Range(.Range("B12:M31"), .Range("B12:M31"))
        rngBody.Copy
    End With

    With objMail
        .Subject = "Sample"
        .To = "chu@chuchu.com"
        wordDoc.Range.PasteAndFormat wdChartPicture & .htmlbody = " " 

'I've tried this 3 instances         
        signature = objMail.body
        '.body = signature
        'htmlBody = signature  
        .Display
    End With

我是否走在正确的道路上?因为所有这些只被模板覆盖。感谢。

1 个答案:

答案 0 :(得分:0)

首先存储签名,然后再添加。

Sub sig()

    Dim objMail As mailItem
    Dim signature As String

    Set objMail = CreateItem(0)

    With objMail

        .Display    ' This is necessary to generate the default signature
        signature = objMail.HTMLBody
        Debug.Print signature

        ' Having saved the signature, you can manipulate the body
        .HTMLBody = "test"

        ' Now you can add the saved signature to the end
        .HTMLBody = .HTMLBody & signature

    End With

End Sub