Word.Tips.Net Welcome toWord.Tips.Net

Helpful Links

Tips.Net Home
WordTips Home

Ask a Word Question
Make a Comment

Tips.Net Store

WordTips FAQ
WordTips Premium

Learn Access Now

Beauty Tips
Car Tips
Cleaning Tips
College Tips
Cooking Tips
Excel2007 Tips
ExcelTips
Family Tips
Gardening Tips
Health Tips
Home Tips
Money Tips
Organizing Tips
Pest Tips
Pet Tips
Wedding Tips
Word2007 Tips
WordTips

Advertise on the
WordTips Site

Newest Tips

Underlining Quoted Text

Changing Tabs Using the Ruler

Moving Drawing Objects

Standardizing Note Reference Placement

Selecting Printing of Color Pictures

Stubborn Foreign Languages

Sizing the Preview Pane

 

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

Find and Replace Almost Anything! An invaluable resource for learning how to harness the full power of Word's search and replace capabilities. You'll discover everything you need in order to master all the intricacies of finding and replacing elements of your document, including the super-powerful "wildcard searches" available in Word.
 
Check out WordTips: Find and Replace today!