vba - 如何在 Outlook 中添加默认签名

标签 vba ms-access outlook

我正在 Access 中编写一个 VBA 脚本,用于创建并自动填充几十封电子邮件。到目前为止,编码很顺利,但我是 Outlook 新手。创建 mailitem 对象后,如何将默认签名添加到电子邮件

  1. 这将是创建新电子邮件时自动添加的默认签名。

  2. 理想情况下,我只想使用 ObjMail.GetDefaultSignature ,但我找不到类似的东西。

  3. 目前,我正在使用下面的函数(在互联网上找到 elsewhere)并引用 htm 文件的确切路径和文件名。但这将由多个人使用,他们的默认 htm 签名文件可能有不同的名称。所以这可行,但并不理想:

    Function GetBoiler(ByVal sFile As String) As String
    'Dick Kusleika
    Dim fso As Object
    Dim ts As Object
    Set fso = CreateObject("Scripting.FileSystemObject")
    Set ts = fso.GetFile(sFile).OpenAsTextStream(1, -2)
    GetBoiler = ts.readall
    ts.Close
    End Function
    

    (使用 getboiler(SigString = "C:\Users\" & Environ("username") & "\AppData\Roaming\Microsoft\Signatures\Mysig.txt") 调用)

编辑

感谢 JP(请参阅评论),我意识到默认签名一开始会显示,但当我使用 HTMLBody 将表格添加到电子邮件时它会消失。所以我想我现在的问题是:如何显示默认签名并仍然显示 html 表格?

Sub X()
    Dim OlApp As Outlook.Application
    Dim ObjMail As Outlook.MailItem

    Set OlApp = Outlook.Application
    Set ObjMail = OlApp.CreateItem(olMailItem)

    ObjMail.BodyFormat = olFormatHTML
    ObjMail.Subject = "Subject goes here"
    ObjMail.Recipients.Add "Email goes here"

    ObjMail.HTMLBody = ObjMail.Body & "HTML Table goes here"
    ObjMail.Display

End Sub

最佳答案

下面的代码将创建 Outlook 消息并保留自动签名

Dim OApp As Object, OMail As Object, signature As String

Set OApp = CreateObject("Outlook.Application")
Set OMail = OApp.CreateItem(0)

With OMail
    .Display
End With

signature = OMail.body

With OMail
    '.To = "someone@somedomain.com"
    '.Subject = "Type your email subject here"
    '.Attachments.Add
    .body = "Add body text here" & vbNewLine & signature
    '.Send
End With

Set OMail = Nothing
Set OApp = Nothing

关于vba - 如何在 Outlook 中添加默认签名,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8994116/

相关文章:

ms-access - "LIKE"运算符(operator)在 MS Access 中工作,但在 ADO 中不工作

outlook - 从 Outlook 解析 iCal : how do I tell what the recurrence schedule is for this event?

c# - 无法静默获取 token - Microsoft Graph API 获取用户的 Outlook 组

excel - 在 Excel 中检查契约(Contract)的最新版本

excel - .range() 和 .cell() 相等的方法?

VBA变量昏暗问题

vba - 如何将行列表与 Excel 中的另一个行列表进行比较?

ms-access - MS Access : convert seperate year, day_count 和时间字段到日期/时间

带分组依据的 SQL 不同计数

c# - Outlook 插件 - 搜索全局地址簿