bottom
Great WordTips!
         
Your e-mail address is safe!
Close Note

Tips.Net > WordTips Home > Macros > Temporarily Changing the Printer in a Macro

Temporarily Changing the Printer in a Macro

Summary: If you use a macro to print to a specific printer, that printer becomes the default printer for Word from then on. (Well, at least until you explicitly change the printer.) With the quick technique described in this tip, you can print to any printer you want without the user ever being aware that you had changed from the printer he or she had previously selected. (This tip works with Microsoft Word 97, Word 2000, Word 2002, Word 2003, and Word 2007.)

Shaune has written a macro that prints, to a PDF writer, product information sheets. When he prints to the PDF writer, the macro resets the default printer for the system on which it is running, so that when someone then tries to print regularly (after the macro is finished), Word still assumes the user wants to print to the PDF writer. Shaune is looking for a way for his macro to use the PDF writer temporarily, without resetting the default printer.

The bad news, Shaune, is that you cannot get around resetting the printer. When you reset the ActivePrinter property, then Word assumes that the printer you specify remains the active (default) printer until you specifically reset it.

The good news is that you can also read the ActivePrinter property, which means your macro can save whatever printer the person had selected before the macro was run, and then reset the ActivePrinter property prior to exiting. The result is that the user never notices that the default printer was changed, because your macro sensed the settings and then changed it back. This technique is used in this manner:

Sub PrinterTechnique()
    Dim sCurrentPrinter as String
    Dim sPDFwriter as String
'
' perform whatever tasks need to be done prior to printing
' make sure you also initialize the sPDFwriter string with
'   the name of your PDF writer
'
    ' save current printer name
    sCurrentPrinter = Application.ActivePrinter

    ' set to name of PDF writer
    Application.ActivePrinter = sPDFwriter

    ' print the document any way desired
    ActiveDocument.PrintOut

    ' change back to the original printer
    Application.ActivePrinter = sCurrentPrinter
'
' continue with the rest of your macro
'
End Sub

Tip #318 applies to Microsoft Word versions: 97 | 2000 | 2002 | 2003 | 2007


Create and Merge! Discover how to use Word's mail merge tool to create your own custom documents. WordTips: Mail Merge Magic includes all the information you need to make your merges more productive.

Helpful Links

Ask a Word Question
Make a Comment

Tips.Net Home
Vital News Home

WordTips FAQ
WordTips Premium

Learn Access Now

Beauty Tips
Bugs and Pests Tips
Car Tips
Cleaning Tips
College Tips
Cooking Tips
Excel2007 Tips
ExcelTips
Family Tips
Gardening Tips
Health Tips
Home Tips
Money Tips
Organizing Tips
Pet Tips
Word2007 Tips
WordTips

Advertise on the
WordTips Site

 

Great Info!

Get tips like this every week in WordTips, a free productivity newsletter. Enter your e-mail address and click "Subscribe."
     
(Your e-mail address will never be shared with anyone, ever.)