Select the product you need help with
- Internet Explorer
- Windows Phone
- More products
XL2000: How to Use Visual Basic Constants in Text Strings
Article ID: 211774 - View products that this article applies to.
This article was previously published under Q211774
Microsoft Visual Basic for Applications includes a number of intrinsic constants that you can use in macro code to insert certain formatting characters, such as tabs, line feeds, and carriage returns. This article contains information about using these constants and about issues that may occur when you use them.
Microsoft provides programming examples for illustration only, without warranty either expressed or implied, including, but not limited to, the implied warranties of merchantability and/or fitness for a particular purpose. This article assumes that you are familiar with the programming language being demonstrated and the tools used to create and debug procedures. Microsoft support professionals can help explain the functionality of a particular procedure, but they will not modify these examples to provide added functionality or construct procedures to meet your specific needs.
If you have limited programming experience, you may want to contact a Microsoft Certified Partner or Microsoft Advisory Services. For more information, visit these Microsoft Web sites:
Microsoft Certified Partners - https://partner.microsoft.com/global/30000104
Microsoft Advisory Services - http://support.microsoft.com/gp/advisoryservice
For more information about the support options that are available and about how to contact Microsoft, visit the following Microsoft Web site:http://support.microsoft.com/default.aspx?scid=fh;EN-US;CNTACTMS
(http://support.microsoft.com/default.aspx?scid=fh;en-us;cntactms)The constants referred to in the "Summary" section are listed in the following table.
You can use these constants anywhere in Visual Basic code that you want them to appear. For example, you can use them to display a multi-line message in a message box, as in the following example:
Constant Definition ------------------------------------------------------------------- vbBack A backspace character [Chr(8)] vbCr A carriage return [Chr(13)] vbCrLf A carriage return and line feed [Chr(13) + Chr(10)] vbLf A linefeed [Chr(10)] vbNewLine A platform-specific new line character, either [Chr(13) + Chr(10)] or [Chr(13)] vbNullChar A null character of value 0 [Chr(0)] vbNullString A string of value 0 [no Chr code]; note that this is not the same as "" vbTab A tab character [Chr(9)]
Make sure that you do not enclose the constants in quotation marks; if you do, the constants appear in the text string instead of as the characters that they represent.
When you use these constants, you may notice the following issues.
Text Boxes and CellsIn Excel 2000, if you use these constants when you insert text into a text box or into a cell, a square character may appear in the text box or cell. This behavior occurs if you use any of the following constants:
Message Boxes (MsgBox)All of the constants listed in this article work correctly when used in a MsgBox, with the exception of the following: