Adding new lines in plain text to outlook message

G

Guest

Module is created with following code (Using Microsoft Outlook Object
Library 10):


Sub SendMessage(MessageBody As String)
Dim objOutlook As Outlook.Application
Dim objOutlookMsg As Outlook.MailItem
Dim objOutlookRecip As Outlook.Recipient
Dim objOutlookAttach As Outlook.Attachment

' Create the Outlook session.
Set objOutlook = CreateObject("Outlook.Application")

' Create the message.
Set objOutlookMsg = objOutlook.CreateItem(olMailItem)

With objOutlookMsg
' Add the To recipient(s) to the message.
Set objOutlookRecip = .Recipients.Add("rse022")
objOutlookRecip.Type = olTo

' Add the CC recipient(s) to the message.
Set objOutlookRecip = .Recipients.Add("rse022")
objOutlookRecip.Type = olCC

' Set the Subject, Body, and Importance of the message.
.Subject = "Message subject"
.Body = (MessageBody)

.Importance = olImportanceHigh 'High importance
.BodyFormat = olFormatPlain

' Resolve each Recipient's name.
For Each objOutlookRecip In .Recipients
objOutlookRecip.Resolve
Next
objOutlookMsg.Display

End With
Set objOutlookMsg = Nothing
Set objOutlook = Nothing
End Sub

Therefore the string MessageBody is inserted in the email body. Note
that the message must be in plaint text because it feeds an automated
system. Which characters to use or how to add new lines in the body of
the new e-mail message instead of one stream of characters?
 
J

John Nurick

This sort of thing:

MessageBody = "First Line"

MessageBody = MessageBody & vbCrLf & "Second line"

MessageBody = MessageBody & vbCrLf _
& "Third Line" & vbCrLf _
& "Fourth Line."

vbCrLf is Chr(13) & Chr(10)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top