E-mail macro

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi,

When using the visual basic macro to send e-mails via outlook, how can I
insert line breaks into the text of the e-mail message so that they appear
when the e-mail is sent?

When I try and do it by pressing return in the macro, that part of it turns
red and does not send.

Can you help please?

Thanks!
 
Hi

Dim strbody As String
strbody = "Hi there" & vbNewLine & vbNewLine & _
"This is line 1" & vbNewLine & _
"This is line 2" & vbNewLine & _
"This is line 3" & vbNewLine & _
"This is line 4"

Or try this if you want to use cell values

Dim cell As Range
Dim strbody As String
For Each cell In ThisWorkbook.Sheets("Sheet1").Range("C1:C60")
strbody = strbody & cell.Value & vbNewLine
Next


Dim strbody As String
With ThisWorkbook.Sheets("Sheet1")
strbody = "Hi there" & vbNewLine & vbNewLine & _
.Range("A1") & vbNewLine & _
.Range("A2") & vbNewLine & _
.Range("A3") & vbNewLine & _
.Range("A4")
End With


Change the Body line to .Body = strbody to use the string.


See also
http://www.rondebruin.nl/sendmail.htm
 
Hi Ron,

I knew you would have the answer to that one. Would using "& Chr(13)" work
as well?

Thanks,
Paul
 
Hi Paul

Would using "& Chr(13)" work
Yes

Sub test()
Dim strbody As String
strbody = "Hi there" & Chr(13) & Chr(13) & _
"This is line 1" & Chr(13) & _
"This is line 2" & Chr(13) & _
"This is line 3" & Chr(13) & _
"This is line 4"

MsgBox strbody

End Sub

You can also send a range or sheet or info you have in a txt file in the body
See my site for more info
 
Back
Top