宏发送模板

问题描述 投票:0回答:1

我有一个很长的电子邮件,我需要使用宏发送给我们的提供商。我已经尝试将电子邮件设置为函数,然后调用函数,但我达到了最大回车数。

我想让电子邮件成为一个模板,以便更容易更新然后发送。到目前为止,我所拥有的是它,它适用于较短的消息,我的消息很长,所以我认为模板将是最好的。

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 = "[email protected]"

    Email_Send_To = "[email protected]"
    Set objOutl = CreateObject("Outlook.Application")
    Set objMailItem = objOutl.CreateItem(olMailItem)

    objMailItem.Display
    strEmailAddr = "[email protected]"
    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 
    [email protected]."
    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
excel vba templates outlook
1个回答
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

这是我的结果:

enter image description here

© www.soinside.com 2019 - 2024. All rights reserved.