Printer Object and Printers Collection

Since it's part of the VB library, the Printer object isn't available to VBA applications. When you write a VBA (as opposed to VB) program, you simply make use of the host application's own built-in printing functionality. For example:

Set oWordActiveDoc = oWord.Documents.Add
Set oWordSel = oWord.Selection
            
oWordSel.TypeText "This is text coming in from the VB app."
oWordSel.WholeStory
oWordSel.Font.Name = "Arial"
oWordSel.Font.Size = 12
oWordSel.Font.Bold = wdToggle

oWordActiveDoc.PrintOut

Printer Object

  • Visual Basic contains a global printer object, which refers to the default printer for the current system. Because this object is global to all parts of the VB project, you don't need to create an object variable; you can simply use the Printer object directly. For example:

    If Printer.Duplex Then
  • The global printer object is also a virtual document onto which you place your text output using the Print method and a range of built-in graphics methods. For example:

    Printer.Print "Private and Confidential"
    Printer.Line (0, 100)-(Printer.ScaleWidth, 100)
  • You can position text and drawings precisely in output by using the Printer object's CurrentX and CurrentY properties. The coordinate system of the printer object is based from the top left corner of the object. The default coordinate unit is a Twip, but this can be changed by using the ScaleHeight, ScaleWidth, ScaleLeft, ScaleTop, and ScaleMode properties.

  • Because the output of proportional fonts ...

Get VB & VBA in a Nutshell: The Language now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.