从 Excel VBA 将签名插入 Outlook 电子邮件 [英] Inserting Signature into Outlook email from Excel VBA

查看:43
本文介绍了从 Excel VBA 将签名插入 Outlook 电子邮件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用 VBA for Excel 自动处理一些电子邮件.到目前为止一切都很好,除了我试图在电子邮件中保留我的签名.

I am trying to automate some emails using VBA for Excel. Everything so far is fine, except trying to keep my signature in the email.

一旦您告诉 VBA 创建新电子邮件,它就已经包含您的默认签名.如果您尝试 Outmail.Display,就可以看到这一点.但是,如果您覆盖 .HTMLBody 属性,它将被删除.

Once you tell VBA to create a new email, it will already contain your default signature. This can be seen if you try Outmail.Display. However if you overwrite the .HTMLBody property, it will be deleted.

我的简单尝试是将 .HTMLBody 的内容保存到 signature(字符串),然后将其重新分配给 .HTMLBody测试一下.但是,生成的电子邮件将没有任何签名.

My simple attempt was to save the contents of .HTMLBody to a signature (string), and then reassign it to .HTMLBody just to test it out. However the resulting email will be void of any signature.

复制和重新插入签名的代码:

Code to copy and re-insert the signature:

Dim myOlApp As Outlook.Application
Dim MyItem As Outlook.MailItem

Dim signature As String


Set myOlApp = CreateObject("Outlook.Application")
Set Outmail = myOlApp.CreateItem(0)

signature = Outmail.HTMLBody
Outmail.HTMLBody = signature

Outmail.Display

显示自动插入签名的代码:

Code to show that signature is automatically inserted:

Dim myOlApp As Outlook.Application
Dim MyItem As Outlook.MailItem 
Set myOlApp = CreateObject("Outlook.Application")
Set Outmail = myOlApp.CreateItem(0)
Outmail.Display

我尝试用 .Body 替换 .HTMLBody.那行得通,但显然去掉了签名的 HTML 格式

I tried replacing .HTMLBody with .Body. That works, but obviously takes out the HTML formatting of the signature

编辑 2:代码在我朋友的电脑上有效,但在我的电脑上无效

Edit 2: The code works on my friend's computer but not on mine

推荐答案

已解决.只需重新启动 Outlook 即可解决.

Solved. Simply restarting Outlook solved it.

这篇关于从 Excel VBA 将签名插入 Outlook 电子邮件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆