Using Carriage Feed and/or Line Feed in string variable

dougdrex

Board Regular
Joined
Sep 27, 2013
Messages
79
I'm using Excel 2010.

This seems like a fairly basic function, but I'm having trouble getting it to work the way I intend.

I have a string variable that is being passed through to the body of an email. There are different pieces of information stored in named ranges of the Excel file that need to be passed through to the variable, and there should be a new paragraph when each section begins.

Below is the code I have, but it is not working. What am I doing wrong?

Code:
strBodyText = Range("Greeting") & vbCrLf & Range("Body1") & vbCrLf & Range("Body2") & vbCrLf & Range("Sig")


Thanks!
Doug
 

Excel Facts

What is =ROMAN(40) in Excel?
The Roman numeral for 40 is XL. Bill "MrExcel" Jelen's 40th book was called MrExcel XL.
If the email is formatted as HTML, change vbCrLf to "< br >" without the spaces.
 
Last edited:
Upvote 0
If the email is formatted as HTML, change vbCrLf to "< br >" without the spaces.

Now it's giving me a syntax error. Here is the code after I used the "<br>":

Code:
strBodyText = Range("Greeting") & <br> & Range("Body1") & <br> & Range("Body2") & <br> & Range("Sig")
 
Upvote 0
The code for Post #3 should have been as shown below. The "< br >" does not have spaces in the actual code.

Code:
    strBodyText = Range("Greeting") & < br > & Range("Body1") & < br > & Range("Body2") & < br > & Range("Sig")
 
Upvote 0
< br > (sans spaces) has to be in quotes as shown in post #2 .
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,175
Members
453,021
Latest member
Justyna P

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