【问题标题】:How to use line breaks in VBA for an outlook email如何在 VBA 中为 Outlook 电子邮件使用换行符
【发布时间】:2022-10-04 22:16:21
【问题描述】:

我正在尝试在 Excel 中使用 VBA 将这些消息分隔为称呼、正文和签名,这将生成一封自动 Outlook 电子邮件。但是我不能使用换行符将它们分开。愿意帮忙吗?

Dim MyOutlook As Object
Set MyOutlook = CreateObject("Outlook.Application")


Dim MyMail As Object
Set MyMail = MyOutlook.CreateItem(olMailItem)

MyMail.To = "sampleemail@google.com"
MyMail.CC = "sampleemail@google.com"enter code here
MyMail.Subject = "Sample Subject"
MyMail.Body = "Hello Team," & _
              "Please see attached for this month's summary" & _
              "Thanks!" & _
              "Sample Signature"
Attached_File = "C:\Users\public\Documents\sample_reports.xls"

MyMail.Attachments.Add Attached_File

MyMail.Send

End Sub

【问题讨论】:

  • 尝试使用<br>
  • 如果 <br> 不起作用,请尝试将 vbNewLine 附加到 .Body 中的行尾

标签: excel vba outlook


【解决方案1】:

使用 vbNewLine

MyMail.Body =  "Hello Team," & vbNewLine & _
               "Please see attached for this month's summary" & vbNewLine & _
               "Thanks!" & vbNewLine & _
               "Sample Signature"

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2018-10-21
    • 2011-09-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-08-15
    • 1970-01-01
    相关资源
    最近更新 更多