Gingie
Gingie

Reputation: 211

How do I keep newline spacing in a cell when putting cell value into VBA and moving to Outlook?

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!

Upvotes: 0

Views: 124

Answers (1)

braX
braX

Reputation: 11755

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 />")

Upvotes: 1

Related Questions