Outlook电子邮件和签名从Excel VBA - .Body vs .HTMLbody [英] Outlook Email and Signature from Excel VBA - .Body vs .HTMLbody
问题描述
我的工作表上有一个按钮发送电子邮件(加上更多,但不重要)。我想要我的默认签名与HTML格式,但两个选项都不会产生我想要的结果:
I have a button on my worksheet to send an email (plus more, but not important). I want my default signature with its HTML formatting but neither option is producing the results I want:
-
.Body
生成正确的正文(字体和回车符),但签名是纯文本
.Body
produces the correct body (fonts and carriage returns) but the signature is plain text
。 HMTLBody
产生正确的签名,但是由于某种原因而导致正文,字体会转到Times New Roman而不是默认的Calibri,而不管我是否使用 vbNewLine
, vbCr
或 vbCrLf
.HMTLBody
produces the correct signature but the body for some reason, the font goes to Times New Roman instead of the default Calibri, and the carriage returns don't work whether I use vbNewLine
, vbCr
, or vbCrLf
我只是SOL?我需要选择一个来处理它,还是有办法让我吃蛋糕呢?
Am I just S.O.L.? Do I need to just pick one and deal with it, or is there a way for me to have my cake and eat it too?
代码: strong>
Code:
.Display ' need to display email first for signature to work
.Subject = Title
.To = ActiveSheet.Range("E10").Value ' <-- Put email of the recipient here
.CC = "" ' <-- Put email of 'copy to' recipient here
.HTMLBody = "Thank you for the opportunity to bid on " & ActiveSheet.Range("B9").Value & ". " & _
" Please read our attached proposal in its entirety to be sure of all inclusions, exclusions, and products proposed. Give us a call with any questions or concerns." & _
vbCrLf & vbCrLf & _
"Thank you," & _
.HTMLBody ' Adds default signature
.Attachments.Add PdfFile
更新:
最后的工作代码,由于以下两个答案的帮助:
.Display ' We need to display email first for signature to be added
.Subject = Title
.To = ActiveSheet.Range("E10").Value
.CC = ""
.HTMLBody = "<font face=""calibri"" style=""font-size:11pt;"">Thank you for the opportunity to bid on " & ActiveSheet.Range("B9").Value & ". " & " Please read our attached proposal in its entirety to be sure of all inclusions, exclusions, and products proposed. Give us a call with any questions or concerns." & _
"<br><br>" & _
"Thank you," & _
.HTMLBody & "</font>" ' Adds default signature
.Attachments.Add PdfFile
推荐答案
p>当您设置HTMLBody属性时,请确保将现有的 HTMLBody
(带有签名)和新数据合并 - 您不能仅连接两个HTML字符串并且期望有效HTML。
找到< body
字符串的位置,找到下一个>的位置(用属性来处理body元素),在>之后插入数据。
When you set the HTMLBody property, make sure you merge the existing HTMLBody
(with the signature) and your new data - you cannot just concatenate two HTML strings and expects a valid HTML.
find the position of the "<body"
string, find the position of the next ">" (to take care of the body elements with attributes), insert your data after that ">".
这篇关于Outlook电子邮件和签名从Excel VBA - .Body vs .HTMLbody的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!