(vba) Generate mail with data in cel - Enters are gone

roelandwatteeuw

Board Regular
Joined
Feb 20, 2015
Messages
87
Office Version
  1. 365
Platform
  1. Windows
Hi all

What I have:
At this moment I have an Excel with a (working) vba code to generate a mail.
This mail is used as a template. So, same tekst (with some variable data from cells), every time .

What I need:
Now, I want this template mail to be editable by the user.
So I wrote the text in a cell and made vba read out this cell.

Problem:
When the mail is generated, all the 'Enters' are gone.

Simple Code before:
VBA Code:
Dim OutApp As Object
Dim OutMail As Object
Dim strbody As String
Set OutApp = CreateObject("Outlook.Application")
Set OutMail = OutApp.CreateItem(0)

strbody = "<BODY style=font-size:11pt;font-family:Calibri>" & _
                    Sheets("Admin").Range("C8").Value & _
                    "<br><br>" & _
                    "This is an example " & "<br>" & _
                    "Some text here" & "<br>" & _
                    "Some more over here" & "<br>" & _
                    "Ending here:" & "<br>" & _
                    "<br>" & _
                    "Please contact me"

   On Error Resume Next

With OutMail
    .Display
    .To = Sheets("Admin").Range("B8").Value
    .CC = ""
    .BCC = ""
    .Subject = "This is the subject"
    .HTMLBody = strbody & .HTMLBody
    '.Send
End With


What I've changed:
In sheet 'Admin' I placed the text in cel B64 (making use of 'Alt + Enter' for the next line)
1591691297947.png


I changed the 'strbody' in the vba-code to:
VBA Code:
strbody = "<BODY style=font-size:11pt;font-family:Calibri>" & _
                    Sheets("Admin").Range("C8").Value & _
                    "<br><br>" & _
                    Sheets("Admin").Range("B64").Value

Result:
The 'Enters' are gone and replaced by 'Spaces'.

1591691253014.png


I hope there's an easy solution for this problem.
Hope you can help!

Thanks!
R.
 

Attachments

  • 1591690603700.png
    1591690603700.png
    4.3 KB · Views: 2
  • 1591690678079.png
    1591690678079.png
    7.9 KB · Views: 3
  • 1591691223992.png
    1591691223992.png
    7.8 KB · Views: 3

Excel Facts

When they said...
When they said you are going to "Excel at life", they meant you "will be doing Excel your whole life".

Forum statistics

Threads
1,215,766
Messages
6,126,758
Members
449,336
Latest member
p17tootie

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top