0

How is it going,

I am trying to make a super simple automated email script that sends quick update emails on project statuses. Trying not to loop to death, I put all update comments in one cell with a newline char(10) for each point. Example: Excel Cells being put into Email

When I try to translate that into VBA, I lose the Char(10):

Output in Email

Below is the section I am struggling with

             strUpdateNotes = Range("D" & i).Text
                    olNewMail.HTMLBody = "Happy Friday!" & _
                                        "<br />" & _
                                        "<br />" & _
                                        "Weekly Project Update!" & _
                                        "<br />" & _
                                        "<br />" & _
                                        "Current Comments on the project:" & _
                                        "<br />" & _
                                        strUpdateNotes & _
                                        "<br />" & _
                                        "<br />" & _
                                        "Let me know if you have any questions. Have a fantastic weekend!"

Is there a way to keep the newline char(10) from the cell to help with readability in the email?

Thanks!

Gingie
  • 129
  • 1
  • 7
  • 1
    Assuming it's actually JUST a `Chr(10)` then - `strUpdateNotes = Replace(Range("D" & i).Text, vbLf, "
    ")` - other possibilities: `strUpdateNotes = Replace(Range("D" & i).Text, vbCr, "
    ")` or `strUpdateNotes = Replace(Range("D" & i).Text, vbCrLf, "
    ")`
    – braX Nov 22 '21 at 04:26
  • 1
    Worked like a freaking charm! Thank you so much! – Gingie Nov 22 '21 at 04:31
  • **1.** Avoid the use of `.Text`. You may want to see [What is the difference between .text, .value, and .value2?](https://stackoverflow.com/questions/17359835/what-is-the-difference-between-text-value-and-value2) **2.** Fully qualify the range `Range("D" & i).Value2`. Without qualifying, it will refer to activesheet, which may or may not be the worksheet you think it is. For example `Thisworkbook.Sheets("Sheet1").Range("D" & i).Value2` – Siddharth Rout Nov 22 '21 at 06:55

1 Answers1

1

Assuming it's actually JUST a Chr(10) then

strUpdateNotes = Replace(Range("D" & i).Text, vbLf, "<br />") 

other possibilities:

strUpdateNotes = Replace(Range("D" & i).Text, vbCr, "<br />") 

or

strUpdateNotes = Replace(Range("D" & i).Text, vbCrLf, "<br />")
braX
  • 11,506
  • 5
  • 20
  • 33