宏发送模板
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了宏发送模板相关的知识,希望对你有一定的参考价值。
我有一个很长的电子邮件,我需要使用宏发送给我们的提供商。我已经尝试将电子邮件设置为函数,然后调用函数,但我达到了最大回车数。
我想让电子邮件成为一个模板,以便更容易更新然后发送。到目前为止,我所拥有的是它,它适用于较短的消息,我的消息很长,所以我认为模板将是最好的。
Sub Sample_Auto_Generated_Email()
Dim Email_Subject, Email_Send_From, Email_Send_To, _
Email_Cc, Email_Body As String
Dim Mail_Object, Mail_Single As Variant
Email_Subject = "Sample MAR Email"
Email_Send_From = "Richard.Sabbara@x.com"
Email_Send_To = "Richard.Sabbara@x.com"
Set objOutl = CreateObject("Outlook.Application")
Set objMailItem = objOutl.CreateItem(olMailItem)
objMailItem.Display
strEmailAddr = "Richard.Sabbara@x.com"
objMailItem.Recipients.Add strEmailAddr
objMailItem.Subject = "Sample"
objMailItem.Body = GetMessageBody()
objMailItem.Send
Set objMailItem = Nothing
Set objOutl = Nothing
End Sub
' This Function has been added.
Function GetMessageBody() As String
GetMessageBody = "Good Afternoon" & vbNewLine & _
Chr(10) & _
"Attached is your Monthly Action Report (MAR) for May 2018." & vbNewLine & _
Chr(10) & _
"This report has been password protected with your practice password provided
to you by your ACOP Care Coordinator in April 2018." & vbNewLine & _
Chr(10) & _
"Technical questions (such as, how to access the MAR, password issues, not
receiving the email, etc.), please contact the Physician Engagement team at
providerservices@ax.com."
Chr (10) & _
"Questions related to the patient data contained within the MAR, please `enter code here`
contact your ACO Partner Care Coordinator."
Chr (10) & _
"Thank you,"
End Function
答案
您可以创建名为.docx的后缀的文档,将模板放在此文档中。
将代码替换为以下代码:
Sub Sample_Auto_Generated_Email()
Dim Email_Subject, Email_Send_From, Email_Send_To, _
Email_Cc, Email_Body As String
Dim Mail_Object, Mail_Single As Variant
Dim wd As Object, editor As Object
Dim doc As Object
Dim oMail As MailItem
Set wd = CreateObject("Word.Application")
Set doc = wd.documents.Open("D:aa.docx")
doc.Content.Copy
doc.Close
Set wd = Nothing
Email_Subject = "Sample MAR Email"
Email_Send_From = “"
Email_Send_To = ""
Set objOutl = CreateObject("Outlook.Application")
Set objMailItem = objOutl.CreateItem(olMailItem)
objMailItem.Display
strEmailAddr = ""
objMailItem.Recipients.Add strEmailAddr
objMailItem.Subject = "Sample"
objMailItem.BodyFormat = olFormatRichText
Set editor = objMailItem.GetInspector.WordEditor
editor.Content.Paste
'objMailItem.htmlBody =
objMailItem.Send
Set objMailItem = Nothing
Set objOutl = Nothing
End Sub
这是我的结果:
以上是关于宏发送模板的主要内容,如果未能解决你的问题,请参考以下文章