#1   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 8
Default E-mail macro

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!
  #2   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 11,123
Default E-mail macro

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

--
Regards Ron de Bruin
http://www.rondebruin.nl



"G and (ajk)" wrote in message ...
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!



  #3   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 1,311
Default E-mail macro

Hi Ron,

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

Thanks,
Paul

"Ron de Bruin" wrote in message
...
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

--
Regards Ron de Bruin
http://www.rondebruin.nl



"G and (ajk)" wrote in message
...
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!





  #4   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 11,123
Default E-mail macro

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


--
Regards Ron de Bruin
http://www.rondebruin.nl



"PCLIVE" wrote in message ...
Hi Ron,

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

Thanks,
Paul

"Ron de Bruin" wrote in message ...
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

--
Regards Ron de Bruin
http://www.rondebruin.nl



"G and (ajk)" wrote in message ...
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!







Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
link to combobox legepe Excel Discussion (Misc queries) 4 July 26th 06 04:45 PM
Compiling macro based on cell values simonsmith Excel Discussion (Misc queries) 1 May 16th 06 08:31 PM
Mail Merge macro Wonder Women Excel Discussion (Misc queries) 4 January 5th 06 07:37 PM
Closing File Error jcliquidtension Excel Discussion (Misc queries) 4 October 20th 05 12:22 PM
Highlight Range - wrong macro, please edit. Danny Excel Worksheet Functions 8 October 19th 05 11:11 PM


All times are GMT +1. The time now is 05:34 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"