How to insert line separator when sending email using VBA Access
Using the "Outlook.Application" object, I am sending an email using VBA Access. In the body, I put the line like this:
Email = "Random things" & Chr(13) _
& "More random things" & Chr(13) _
If I show a line Email
in MsgBox
, it displays correctly, but when I submit it, the lines are removed.
I tried:
-
Chr(13)
-
vbCrLf
-
vbCr
But all three have the same result:
+3
source to share
1 answer
Try the following:
Sub OutlookEmail()
Dim AppOutlook As Outlook.Application
Set AppOutlook = CreateObject("Outlook.application")
Dim Mail As MailItem
Set Mail = AppOutlook.CreateItem(olMailItem)
Dim Email As String
Email = "Random things" & vbNewLine _
& "More random things" & vbNewLine
'Generate Email
Mail.Subject = "Test Subject"
Mail.To = "Test@test.com"
Mail.Body = Email
Mail.Display
Set Mail = Nothing
Set AppOutlook = Nothing
End Sub
Tested that my kernel is working correctly on my PC.
+4
source to share