Line break on "Comma" in email body from a single cell

kitsa

Board Regular
Joined
Mar 4, 2016
Messages
111
Office Version
  1. 365
  2. 2016
Hi Guys,
I have a cell [K14] which has "Hi Peter Homes, As attached is the quote you have requested". When I VBA to email body, it doesn't line break, want it to look like below:
Hi Peter Homes,
As attached is the quote you have requested
I have code:

VBA Code:
Private Sub CommandButton1_Click()
'Sub SendExcelFilesAsPDFtoEmail()
 
   Dim OutApp As Object
   Dim OutMail As Object
   Dim Strbody As String, Fname As String
   Dim x As Date
       x = Format(Now() + 1, "MMMM dd, yyyy")
 
    Set OutApp = CreateObject("Outlook.Application")
    Set OutMail = OutApp.CreateItem(0)

    Fname = "EQ" & Range("F19") & ".pdf"

Strbody = Range("K14")

On Error Resume Next

' Create the PDF attachment
  ActiveSheet.ExportAsFixedFormat Type:=x1TypePDF, Filename:=Fname

With OutMail
        .Display
        .To = Range("K11").Value
        .Subject = Range("K13") & " " & x
        .HTMLBody =.HTMLBody & "<br/><br/>" & Replace(Strbody, vbCr, "<br/>")
        .Attachments.Add Fname
        .Importance = 2 'Or olImprotanceHigh Or olImprotanceLow
        .Display
    End With
   
  On Error GoTo 0
   Set OutMail = Nothing
   Set OutApp = Nothing
   Set OutLookMess = Nothing
   Set OutLookNSpace = Nothing
 
End Sub
 
Last edited:

Excel Facts

Excel motto
Not everything I do at work revolves around Excel. Only the fun parts.
Try replacing this ...
Rich (BB code):
.HTMLBody -.HTMLBody & "<br/><br/>" & Replace(Strbody, vbCr, "<br/>")

with this ...
VBA Code:
.HTMLBody -.HTMLBody & "<br/><br/>" & Replace(Strbody, ", ", "," & vbNewLine) & "<br/>"
 
Upvote 0
Hi Rich,
Some how this didn't work, but I noticed my "Strbody" showed up after signature. I have now change code as below, but still no line break.

VBA Code:
.HTMLBody = Replace(Strbody, ", ", "," & vbNewLine) & "<br/>" & "" & .HTMLBody
 

Attachments

  • Capture.JPG
    Capture.JPG
    47.7 KB · Views: 14
Upvote 0
Sorry, HTML is all about text which I overlooked :cry:
Try
VBA Code:
.HTMLBody = Replace(Strbody, ", ", ",<br/>") & "<br/>" & "" & .HTMLBody
 
Upvote 0
Solution
Sorry, HTML is all about text which I overlooked :cry:
Try
VBA Code:
.HTMLBody = Replace(Strbody, ", ", ",<br/>") & "<br/>" & "" & .HTMLBody
Hi Gwteb,
Worked perfecto!! but the text is now small, how do I fix that?
 

Attachments

  • Capture.JPG
    Capture.JPG
    46.3 KB · Views: 18
Upvote 0
To be honest I have no idea. I should Google, but you can do that yourself.
In cases where I need it, I use Word as an editor, so I'm able to manipulate everything much easier, insert Excel tables and images, and so on.
 
Upvote 0
Thanks Anyway. I worked it out

VBA Code:
.HTMLBody = "<p style='font-family:calibri;font-size:14.5'>" & Replace(Strbody, ", ", ",<br/>") & "<br/>" & "" & "</p>" & .HTMLBody
 
Upvote 0
Glad it's sorted and thanks for letting me know.
 
Upvote 0

Forum statistics

Threads
1,214,643
Messages
6,120,707
Members
448,981
Latest member
recon11bucks

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