【发布时间】:2018-09-25 22:27:11
【问题描述】:
我尝试将电子邮件设置为函数,但我达到了最大回车数。
我想将电子邮件设为模板,以便更轻松地更新然后发送。
我所拥有的适用于较短的消息。我的信息很长,所以我认为最好使用模板。
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
【问题讨论】:
-
代码有效,我希望它发送电子邮件模板而不是嵌入式消息。如果我的模板名为 temp.oft,我希望它为消息打开它。
-
我找到了以下代码并打开了模板,我只需要添加收件人、发件人、抄送、主题行和附件。 Sub OutlookTemplate1() Dim myolapp As Object Dim myitem As Object Set myolapp = CreateObject("Outlook.Application") myolapp.Session.Logon '修改文件的链接和标题以使用您的示例 Set myitem = myolapp.CreateItemFromTemplate(" C:\Users\e4h7x8r\Desktop\Test_Templates.oft") myitem.Display '或发送 End Sub
-
你不应该在这里使用函数
-
您可能只想使用内置的template 并使用vba 来启动它
标签: excel vba templates outlook