vba 添加outlook 签名_如何添加默认的签名在Outlook

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

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值