Insert line break in email from vba code

J

jh3016

I am trying to insert a line break. I have a button that the user clicks and
then the text goes into Outlook. What is happening is that all of the text
is running together. Does the Chr(10) & Chr(13) work in Outlook?

Private Sub Command29_Click()
On Error GoTo Err_Command0_Click

Dim stext As String
Dim sAddedtext As String

If Len(txtMainAddresses) Then
stext = txtMainAddresses
End If
If Len(txtCC) Then
sAddedtext = sAddedtext & "&CC=" & txtCC
End If
If Len(txtBCC) Then
sAddedtext = sAddedtext & "&BCC=" & txtBCC
End If
If Len(txtSubject) Then
sAddedtext = sAddedtext & "&Subject=" & txtSubject
End If

If Len(txtBody) Then

sAddedtext = sAddedtext & "&Body=" & txtBody & Chr(10) & Chr(13) &
txtProducts1 & txtbody2

End If

'If Len(txtAttachment) Then
' sAddedtext = sAddedtext & "Attach=" & Chr$(34) & txtAttachment & Chr
$(34)
'End If

stext = "mailto:" & stext

If Len(sAddedtext) <> 0 Then
Mid$(sAddedtext, 1, 1) = "?"
End If

stext = stext & sAddedtext

' launch default e-mail program
If Len(stext) Then
Call ShellExecute(hwnd, "open", stext, vbNullString, vbNullString,
SW_SHOWNORMAL)
End If
Exit_Command0_Click:
Exit Sub


Err_Command0_Click:
MsgBox Err.Description
Resume Exit_Command0_Click
'End If
End Sub
 
D

Douglas J. Steele

It's Chr(13) & Chr(10): it must be in that order. Alternatively, in code,
you can use vbCrLf instead.
 

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