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

查看:1094
本文介绍了从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

我尝试将.HTMLBody替换为.Body.可以,但是显然可以去除签名的HTML格式

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

代码可以在我朋友的计算机上工作,而不能在我的计算机上工作

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天全站免登陆