如何添加默认的签名在OutlookOutlook

2023-09-08 10:55:17 作者:与我诉尽平生欢

我写在Access创建并自动填充几十封电子邮件VBA脚本。它已经顺利编码到目前为止,但我是新来的Outlook。在创建的MailItem对象后,我怎么添加默认签名的电子邮件

这将创建一个新的电子邮件时,它会自动添加默认签名。

在理想情况下,我想只使用 ObjMail.GetDefaultSignature ,但我找不到这样的事情。

目前,我使用了以下功能(在网络上其他地方发现)并引用确切的路径和放大器;文件名HTM文件。但是,这将被用于由几个人,他们可能有不同的名称,它们的默认HTM签名文件。所以这个工作,但它不是理想的:

 功能GetBoiler(BYVAL sFile作为字符串)作为字符串
迪克Kusleika
昏暗的FSO作为对象
昏暗的TS作为对象
设置FSO =的CreateObject(Scripting.FileSystemObject的)
集TS = fso.GetFile(sFile).OpenAsTextStream(1,-2)
GetBoiler = ts.readall
ts.Close
端功能
 
如何设置Outlook邮件签名

(调用方式 getboiler(SigString =C:\用户\&放大器; ENVIRON(用户名)及\应用程序数据\漫游\微软\签名\ Mysig.txt)

修改

由于JP(见注释),我认识到,默认的签名显示了在第一,但它消失,当我使用HTMLBody到一个表添加到电子邮件。所以,我想我的问题是现在?我怎么显示默认的签名,仍然显示一个HTML表格

 子X()
    昏暗OlApp作为Outlook.Application
    昏暗ObjMail作为Outlook.MailItem

    设置OlApp = Outlook.Application
    设置ObjMail = OlApp.CreateItem(olMailItem)

    ObjMail.BodyFormat = olFormatHTML
    ObjMail.Subject =主题放在这里
    ObjMail.Recipients.Add电子邮件到这里

    ObjMail.HTMLBody = ObjMail.Body和放大器; HTML表格放在这里
    ObjMail.Display

结束小组
 

解决方案

在code以下将创建一个Outlook消息和;保持自动签​​名

 昏暗OApp为对象,OMail为对象,签名作为字符串
设置OApp =的CreateObject(Outlook.Application)
设置OMail = OApp.CreateItem(0)
    随着OMail
    。显示
    结束与
        签名= OMail.body
    随着OMail
    '。为了=someone@somedomain.com
    .Subject =输入你的电子邮件的主题在这里
    .Attachments.Add
    。体=添加正文这里&放大器; vbNewLine和放大器;签名
    '。发送
    结束与
设置OMail =什么
设置OApp =什么
 

I am writing a VBA script in Access that creates and auto-populates a few dozen emails. It's been smooth coding so far, but I'm new to Outlook. After creating the mailitem object, how do I add the default signature to the email?

This would be the default signature that is automatically added when creating a new email.

Ideally, I'd like to just use ObjMail.GetDefaultSignature, but I can't find anything like it.

Currently, I'm using the function below (found elsewhere on the internet) and referencing the exact path & filename of the htm file. But this will be used by several people and they may have a different name for their default htm signature file. So this works, but it's not ideal:

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

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

Edit

Thanks to JP (see comments), I realize that the default signature is showing up at first, but it disappears when I use HTMLBody to add a table to the email. So I guess my question is now: How do I display the default signature and still display an html table?

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

解决方案

The code below will create an outlook message & keep the auto signature

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