Visual Basic Reference

Printer Object, Printers Collection

See Also    Example    Properties    Methods    Events

The Printer object enables you to communicate with a system printer (initially the default system printer).

The Printerscollection enables you to gather information about all the available printers on the system.

Syntax

Printer

Printers(index)

The index placeholder represents an integer with a range from 0 to Printers.Count-1.

Remarks

Use graphics methods to draw text and graphics on the Printer object. Once the Printer object contains the output you want to print, you can use the EndDoc method to send the output directly to the default printer for the application.

You should check and possibly revise the layout of your forms if you print them. If you use the PrintForm method to print a form, for example, graphical images may be clipped at the bottom of the page and text carried over to the next page.

The Printers collection enables you to query the available printers so you can specify a default printer for your application. For example, you may want to find out which of the available printers uses a specific printer driver. The following code searches all available printers to locate the first printer with its page orientation set to Portrait, then sets it as the default printer:

Dim X As Printer
For Each X In Printers
   If X.Orientation = vbPRORPortrait Then
      ' Set printer as system default.
      Set Printer = X
      ' Stop looking for a printer.
      Exit For
   End If
Next

You designate one of the printers in the Printers collection as the default printer by using the Set statement. The preceding example designates the printer identified by the object variable X, the default printer for the application.

Note   If you use the Printers collection to specify a particular printer, as in Printers(3), you can only access properties on a read-only basis. To both read and write the properties of an individual printer, you must first make that printer the default printer for the application.