Search Blog

Monday, August 2nd, 2010

Line feed in VBA textbox

When you need to create a line feed (new line) in a VBA text box you can do so in the string that you’re using to assemble your message using any one of a number of methods.

You can use Chr(13) which is an old style character conversion of ASCII character 13 which is the carriage return and line feed character. Or you can use vbNewLine or even vbCrLf.

But, try as you might, all you will get in your textbox is a silly paragraph marker and not a new line if you don’t set your textbox up as a multiline text box in its Properties. Don’t say I didn’t warn you!

5 Comments

I have a textbox that I enter data into, and have enterkeybehavior set to true so a new line is created with the Enter key. The problem is that when I save the datastring into an excel spreadsheet and ultimately into a text file, when I bring it back into the form, the returns are missing.

ex:
line1
line2

then save and put back into text box

line1line2

any ideas? I think I need to add a chr(13) with the , but don’t know how to do it

The problem only occurs when I save the spreadsheet to a textfile (I concatenate the fields). Do you know what symbol or character is added to the excel spreadsheet to denote the return or line feed? I tried to copy it into Word, and is shows a little box, but I can’t figure out what it is or what it represents. If I knew, I could search and replace it with chr(13).