Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Add newline to VBA or Visual Basic 6

Tags:

vba

vb6

I want to concatenate two strings with a linebreak between them.

st = "Line 1" + newline + "Line2" 

How do I add a newline to VBA or Visual Basic 6?

like image 723
Gerhard Powell Avatar asked Nov 21 '14 17:11

Gerhard Powell


People also ask

How do I add a new line in VBA?

Example #2 – Insert New Line Using “Char (10)” To a new line instead of “vbNewLine,” we can also use the function CHR to insert a new line in VBA. read more. For example, CHR (10) is the code to insert a new line in VBA.

How do you insert a line break in a text VBA?

For it to appear on separate lines within a text file you will need Chr(13) & Chr(10) or vbCrLf or if you're in excel vba vbNewLine . All of which will provide the needed carriage return Chr(13) and line feed Chr(10) characters to produce a line break.


2 Answers

Visual Basic has built-in constants for newlines:

vbCr = Chr$(13) = CR (carriage-return character) - used by Mac OS and Apple II family

vbLf = Chr$(10) = LF (line-feed character) - used by Linux and Mac OS X

vbCrLf = Chr$(13) & Chr$(10) = CRLF (carriage-return followed by line-feed) - used by Windows

vbNewLine = the same as vbCrLf

like image 81
Gerhard Powell Avatar answered Oct 19 '22 00:10

Gerhard Powell


Use this code between two words:

& vbCrLf & 

Using this, the next word displays on the next line.

like image 41
Gajanan Chitare Avatar answered Oct 19 '22 00:10

Gajanan Chitare