我正在 Access 中编写一个 VBA 脚本,用于创建并自动填充几十封电子邮件。到目前为止,编码很顺利,但我是 Outlook 新手。创建 mailitem 对象后,如何将默认签名添加到电子邮件?
这将是创建新电子邮件时自动添加的默认签名。
理想情况下,我只想使用
ObjMail.GetDefaultSignature
,但我找不到类似的东西。目前,我正在使用下面的函数(在互联网上找到 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/