Environment
- Windows Specification: Windows 10 Pro
- Version: 20H2
Background
I tried sending an email using VBA, but the line breaks in the body did not work properly, and the text was output as a single continuous line. Therefore, I learned how to add line breaks to the email body.
Using “vbCrLf”
It cannot be done with just “&”
Here is the code that did not work. (Only the email body part is shown).
objMail.Body = .Range("D6").Value & _
.Range("D7").Value & _
.Range("D8").Value & _
.Range("D9").Value 'メール本文
I thought that since I was changing cells, simply connecting them with & would create line breaks, but it did not work.
Let’s use “vbCrLf”
Using vbCrLf worked successfully.
objMail.Body = .Range("D6").Value & vbCrLf & _
.Range("D7").Value & vbCrLf & _
.Range("D8").Value & vbCrLf & vbCrLf & _
.Range("D9").Value 'メール本文
Summary
I was able to solve it like this. In my case, the cell values change every time, so I adopted this method. However, if the body text does not change, you can also add line breaks directly inside the cell using “Alt + Enter”.
