O'Reilly logo

VB & VBA in a Nutshell: The Language by Paul Lomax

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required