Email body via VBA

gmazza76

Well-known Member
Joined
Mar 19, 2011
Messages
767
Office Version
  1. 365
Platform
  1. Windows
Good Afternoon,

I am able to email info from a range in a sheet from a copy and paste point, but I would like to make the email more readable. I have looked on line, but am having a bit of trouble with this

The code below puts all the information in the email but I would like to space this out by putting a line in between each so say complaint number shows on one line then a line free and so on like :-

A Complaint has been assigned to your reference: " & Me.ComplaintNo.Value

"This is a complaint for : " & Me.ComboBox5.Value

"Please deal ASAP"

Is this possible?

Code:
With Destwb
        .SaveAs TempFilePath & TempFileName & FileExtStr, FileFormat:=FileFormatNum
        On Error Resume Next
        With OutMail
            .From = "me"
            .To = MyEmail
            .CC = ""
            .BCC = "" 
            .Subject = "Notification for your work queue."
            .Body = "A Complaint has been assigned to your reference: " & Me.ComplaintNo.Value & Chr(10) & _
              "This is a complaint for : " & Me.ComboBox5.Value & Chr(10) &  "Revenue: " & Me.ComboBox3.Value & Chr(10) &  "Please deal ASAP" & Chr(10) & _
[code/]

thanks in advance 
Gavin
 

Excel Facts

Quick Sum
Select a range of cells. The total appears in bottom right of Excel screen. Right-click total to add Max, Min, Count, Average.
Gavin

Does the code you posted not work?

Using Chr(10), or perhaps vbCrLf, should add line returns.
 
Upvote 0
I am getting the error "Expected: Line number or label or statement or end of statement" on the line below

Code:
.Subject = "Notification of Complaint Assigned to you."
            .Body = "A Complaint has been assigned to your reference: " & Me.ComplaintNo.Value & vbCrLf
             [COLOR=#ff0000] "This is a complaint for : [/COLOR]"& Me.ComboBox5.Value  & vbCrLf
              "Revenue: " & Me.ComboBox3.Value & Chr(10) & _
              "" & Chr(10) & _ "Please deal ASAP" & Chr(10)
[code/]

But I have managed to move down a line with no issues.
 
Upvote 0
Think you are missing some line continuation characters, try this.
Code:
.Body = "A Complaint has been assigned to your reference: " & Me.ComplaintNo.Value & vbCrLf & _
        "This is a complaint for : " & Me.ComboBox5.Value & vbCrLf & _
        "Revenue: " & Me.ComboBox3.Value & Chr(10) & _
        "" & Chr(10) & _
        "Please deal ASAP" & Chr(10)
 
Upvote 0
thanks,
I have just entered the code below and am getting "Compile error: Expected: expression" as the code goes red

Code:
            .Body = "A Complaint has been assigned to your reference: " & Me.ComplaintNo.Value & vbCrLf & _
            "This is a complaint for : " & Me.ComboBox5.Value & vbCrLf & _
[code/]

Do I need to enter "& vbCrLf & _" at the end of each code I put in?
Can I also put the code in to create a blank line between each as per below

[code]
.Body = "A Complaint has been assigned to your reference: " & Me.ComplaintNo.Value & vbCrLf & _
        "This is a complaint for : " & Me.ComboBox5.Value & vbCrLf & _
    vbCrLf & _
    "Next Line" & vbCrLf & _
[code/]
Sorry to be a pain, but its good to learn
 
Last edited:
Upvote 0

Forum statistics

Threads
1,214,905
Messages
6,122,175
Members
449,071
Latest member
cdnMech

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top