Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Excel newline formatting to Outlook Email Body and keep format

Status
Not open for further replies.

AVAYANUS

Technical User
May 28, 2015
7
0
0
GB
Hello

I'm hoping you can help with the following. I have created code to create an Outlook email from excel which works fine. The body of the email pulls it's text from a cell in excel and this generally works fine. The excel cell (B20) has new lines and reads something like this.....

1.Went Shopping
2.Came home
3.Went to sleep
4.Woke up

When I pull it into Outlook it looks like this
1.Went Shopping2.Came home3.Went to sleep4.Woke up

I really need it to look like the original in excel

Is this possible to do in VBA

My existing code is as follows

Sub CREATEEMAIL_Click()
Dim OutApp As Object
Dim OutMail As Object
Dim exptrknumber As String
Dim claimantemail As String
Dim ccemail As String
Set OutApp = CreateObject("Outlook.Application")
Set OutMail = OutApp.CreateItem(0)
Backgdetail = [B20]
createemail:
On Error Resume Next
With OutMail
.to = ""
.CC = ""
.BCC = ""
.Subject =”Title”
.BodyFormat = olFormatHTML
.htmlbody = "Please see details of Information below "
.htmlbody = .htmlbody & "<br/><br/><b> BACKGROUND </b>"
.htmlbody = .htmlbody & "<br/><br/>" & Backgdetail
.Display 'or use .Send
End With
On Error GoTo 0
Set OutMail = Nothing
Set OutApp = Nothing

End Sub


Many Thanks
 
I'd replace this:
.htmlbody = .htmlbody & "<br/><br/>" & Backgdetail
with this:
.htmlbody = .htmlbody & "<br/><br/>" & Replace(Backgdetail, vbLF, "<br/>")

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
PHV
Many thanks for the response - It works

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top