我有一封长电子邮件,需要使用宏发送给我们的提供商。我尝试将电子邮件设置为一个函数,然后调用该函数,但是我遇到了回车的最大次数。
我希望将电子邮件作为模板,以便更轻松地进行更新和发送。到目前为止,我所拥有的,并且它适用于短消息,我的消息很长,所以我认为模板是最好的。
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
答案 0 :(得分:2)
您可以创建一个后缀名为.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
这是我的结果: