在电子邮件草稿中添加默认签名

Adding default signature in draft email

提问人:Elaine Perez Canlas 提问时间:10/31/2023 更新时间:10/31/2023 访问量:37

问:

我正在尝试使用excel文件中的VBA代码生成电子邮件草稿。 我无法添加默认签名并保持其格式。我当前的代码可以添加签名,但格式已更改。我应该更改什么才能捕获签名的确切格式,我尝试了.显示并使用了 .HTMLBody,但签名没有显示,而是一些我不明白的超链接。

这是我当前的代码:

Sub DraftEmail()
Dim objOutlook As Outlook.Application
Dim objMail As Outlook.MailItem
Dim lCounter As Long
Dim signature As String

'Set objects
Set objOutlook = Outlook.Application
        
'Show confirmation message to user
    MsgBox "Draft Email Generated.", vbInformation
           
'Create a new draft email
    Set objMail = objOutlook.CreateItem(olMailItem)
    objMail.Display
    signature = objMail.Body

'Read details from Draft Email Sheet
For lCounter = 6 To 6
    
    'To
    objMail.To = Worksheets("Draft Email").Range("A" & lCounter).Value
    
    'Cc
    objMail.CC = Worksheets("Draft Email").Range("B" & lCounter).Value
    
    'Subject
    objMail.Subject = Worksheets("Draft Email").Range("C" & lCounter).Value
    
    'Draft Email Body
    objMail.Body = Worksheets("Draft Email").Range("D" & lCounter).Value & objMail.Body
    
    'Add Attachment
    'objMail.Attachments.Add (Draft Email.Range("E" & lCounter).Value)
    
    'Close the object
    Set objMail = Nothing
Next
End Sub

提前致谢!:)

HTML VBA 电子邮件 签名

评论

0赞 braX 10/31/2023
这回答了你的问题吗?如何在Outlook中添加默认签名

答:

0赞 niton 10/31/2023 #1

出现是混乱的根源。Dim signature As String

Option Explicit

Sub DraftEmail_appendSignatureAsVariant()

Dim objOutlook As Outlook.Application
Dim objMail As Outlook.MailItem

Dim signature As Variant

Dim objOutlook As New Outlook.Application
Set objMail = objOutlook.CreateItem(olMailItem)

objMail.Display
signature = objMail.HTMLBody

objMail.HTMLBody = "Value" & signature

End Sub
0赞 niton 10/31/2023 #2

您可以在不使用签名变量的情况下附加签名。

Sub DraftEmail_AppendHTMLBodyDirectly()

Dim objOutlook As New Outlook.Application
Dim objMail As Outlook.MailItem

Set objOutlook = Outlook.Application
Set objMail = objOutlook.CreateItem(olMailItem)

objMail.Display

objMail.HTMLBody = "Value" & objMail.HTMLBody

End Sub