Multi-line email body when sending emails from excel

10,411

Use VBNewLine for a new line character.

Dim A As String: A = "Line A"
Dim B As String: B = "Line B"
Debug.print(A & VbNewLine & B)

Output:

Line A
Line B
Share:
10,411
grademacher
Author by

grademacher

Updated on June 04, 2022

Comments

  • grademacher
    grademacher almost 2 years

    I am trying to automate sending emails with multiple lines and paragraphs through excel using VBA. Here is the code I have so far:

    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
    

    However I'm not sure how to make the body of the email include line breaks and split up paragraphs rather than just having one block of text.

  • BruceWayne
    BruceWayne over 8 years
    You can also use vbCrLf, i.e. Msgbox("Hello " & vbCrLf & " This is a second line."). (Note sure if it works in Debug.Print but it should).
  • R3uK
    R3uK over 8 years
    Just a warning here because I don't have the exhaustive list in my head, but not all of the "usual" characters to change line works in the body of an Outlook email. But if I remember well, both vbNewLine and vbCrLf should work properly!
  • Amen Jlili
    Amen Jlili over 8 years
    I used vbnewline in the past to send template emails from Excel to Outlook and it works fine!