Skip to main content

Debug.Print method

Table of contents
  1. Syntax
  2. Remarks
  3. Example

Prints text in the Immediate window.

Syntax

object.Print [ outputlist ]

The Print method syntax has the following object qualifier and part:

Part Description
object Optional. An object expression that evaluates to an object in the Applies To list.
outputlist Optional. Expression or list of expressions to print. If omitted, a blank line is printed.

The outputlist argument has the following syntax and parts:

{Spc(n) | Tab(n)} expression charpos

Part Description
Spc(n) Optional. Used to insert space characters in the output, where n is the number of space characters to insert.
Tab(n) Optional. Used to position the insertion point at an absolute column number where n is the column number. Use Tab with no argument to position the insertion point at the beginning of the next print zone.
expression Optional. Numeric expression or string expression to print.
charpos Optional. Specifies the insertion point for the next character. Use a semicolon (;) to position the insertion point immediately following the last character displayed. Use Tab(n) to position the insertion point at an absolute column number. Use Tab with no argument to position the insertion point at the beginning of the next print zone. If charpos is omitted, the next character is printed on the next line.

Remarks

Multiple expressions can be separated with either a space or a semicolon.

All data printed to the Immediate window is properly formatted by using the decimal separator for the locale settings specified for your system. The keywords are output in the appropriate language for the host application.

For Boolean data, either True or False is printed. The True and False keywords are translated according to the locale setting for the host application.

Date data is written by using the standard short date format recognized by your system. When either the date or the time component is missing or zero, only the data provided is written.

Nothing is written if outputlist data is Empty. However, if outputlist data is Null, Null is output. The Null keyword is appropriately translated when it is output.

For error data, the output is written as Error errorcode. The Error keyword is appropriately translated when it is output.

The object is required if the method is used outside a module having a default display space. For example, an error occurs if the method is called in a standard module without specifying an object, but if called in a form module, outputlist is displayed on the form.

Example

Using the Print method, this example displays the value of the variable MyVar in the Immediate window. Note that the Print method only applies to objects that can display text.

Dim MyVar
MyVar = "Come see me in the Immediate pane."
Debug.Print MyVar

The following example prints a blank line in the Immediate window.

Debug.Print

Leave a comment

Your email address will not be published. Required fields are marked *

Format your code: <pre><code class="language-vba">place your code here</code></pre>