【问题标题】:Adding a default signature to outlook email VBA向 Outlook 电子邮件 VBA 添加默认签名
【发布时间】:2013-10-06 22:24:36
【问题描述】:

我正在尝试获取我的默认签名并将其应用到我使用用户表单设置的电子邮件。我尝试了几个选项,包括这个:How to add default signature in Outlook

但它似乎不起作用......

Private Sub addUpdate_Click()
 Dim mailObj As MailItem
 Dim mailBody, signature As String
 Dim oMail, oApp As Object

newUser.Hide

Set oApp = CreateObject("Outlook.Application")
Set oMail = oApp.CreateItem(0)

With oMail
    .Display
End With
signature = oMail.body

Set mailObj = CreateItem(olMailItem)

mailBody = "<HTML><BODY><P>Hi " & firstName.Value & ",</P>" _
            & "<P>Thank you for your interest in the <STRONG>Metropolitan Sales</STRONG> website.</P>" _
            & "<P>Some of the features of the website include:</P>" _
            & "<UL><LI>Placing Orders</LI><LI>Order status & tracking</LI><LI>Detailed product information</LI>" _
            & "<LI>Specification sheets in PDF for all products</LI></UL>" _
            & "<P>These features can be accessed at:</P>" _
            & "<P><a href= 'http://www.metsales.com'>www.metsales.com</a>, then click on Catalog</p>" _
            & "<p><strong>Username : </strong>" & username.Value & "<br>" _
            & "<strong>Password  : </strong>" & password.Value & "</p>" _
            & "<p>Feel free to contact me should you have any questions.</p><br>" _
            & "<p>Thank you,</p>" & signature & "</body></html>"

With oMail
    .Recipients.add (email.Value)
    .Subject = "Metropolitan Sales Username and Password"
    .BodyFormat = olFormatHTML
    .HTMLBody = mailBody
    .Send
 End With
 Unload newUser
End Sub

【问题讨论】:

  • 您永远不会将signature 设置为任何内容。查看您链接到的帖子,您会看到首次创建电子邮件时HTMLBody 签名。您将它存储在 signature 中,然后在最后添加它,就像您当前的代码尝试做的那样。
  • 标记为与How to add default signature in Outlook 重复。如果该帖子或@DougGlancy 的评论未涵盖特定问题,请修改问题:)
  • 还请注意,为了安全起见,您应该正确地Dim mailiBody as String, signature As string
  • 所以我设法让签名工作(当我尝试显示初始邮件项目时我的表单正在显示,它导致了一个错误)但是现在我的问题,据我所知,是因为我的身体是一个 html 身体,签名只是一个普通的身体,它没有按照我想要的方式显示。我重新发布了我更新的代码,但我的签名中有一些 jpeg 链接到 twitter 和 facebook 和其他东西,但现在显示的只是 HYPERLINK 等......和 ​​www.xyz.com

标签: vba email outlook html-email


【解决方案1】:

所以我想出了如何做到这一点...无需创建 oApp 变量,因为它是从正在运行的 Outlook 实例内部调用的。

我还需要将BodyFormat 设置为olFormatHTML

Set oMail = CreateItem(0)
With oMail
    .BodyFormat = olFormatHTML
    .Display
End With
signature = oMail.HTMLBody

【讨论】:

    猜你喜欢
    • 2017-09-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-07-04
    • 1970-01-01
    • 2023-03-18
    • 1970-01-01
    • 2015-10-02
    相关资源
    最近更新 更多