我正在尝试使用VBA通过excel自动发送包含多行和多段的电子邮件。这是我到目前为止的代码:
Sub Send_Email()
Dim Email_Subject, Email_Send_From, Email_Send_To, _
Email_Cc, Email_Bcc, Email_Body As String
Dim Mail_Object, Mail_Single As Variant
Email_Subject = "test"
Email_Send_From = "email"
Email_Cc = ""
Email_Bcc = ""
Dim r As Range, cell As Range, mynumber As Long
Dim i As Long
Set r = Range("K2:K300")
i = 2
For Each cell In r
If Cells(i, "K").Value = "" Then
Else
Email_Send_To = Worksheets("Sheet1").Cells(i,"K").Value
Email_Body = "test from outlook excel"
Set Mail_Object = CreateObject("Outlook.Application")
Set Mail_Single = Mail_Object.CreateItem(0)
With Mail_Single
.Subject = Email_Subject
.To = Email_Send_To
.cc = Email_Cc
.BCC = Email_Bcc
.Body = Email_Body
.send
End With
End If
i = i + 1
Next
On Error GoTo debugs
debugs:
If Err.Description <> "" Then MsgBox Err.Description
End Sub
但是,我不确定如何让电子邮件的正文包括换行符和拆分段落,而不是只有一个文本块。
答案 0 :(得分:2)
将VBNewLine
用于换行符。
Dim A As String: A = "Line A"
Dim B As String: B = "Line B"
Debug.print(A & VbNewLine & B)
输出:
Line A
Line B