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?
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
Use this code between two words:
& vbCrLf &
Using this, the next word displays on the next line.
vbNewLine is preferred because it will select the correct line terminator.Here’s a concise solution for adding a newline in VB6:
Dim myString As String
myString = "Line 1" & vbCrLf & "Line 2"
MsgBox myString
Just use vbCrLf to insert a new line. Alternatively, for constants:
Const NEWLINE As String = vbCrLf
Dim myString As String
myString = "Line 1" & NEWLINE & "Line 2"
MsgBox myString
st = "Line 1" + vbCrLf + "Line2"