Please Note: This article is written for users of the following Microsoft Word versions: 97, 2000, 2002, and 2003. If you are using a later version (Word 2007 or later), this tip may not work for you. For a version of this tip written specifically for later versions of Word, click here: Temporarily Changing the Printer in a Macro.
by Allen Wyatt
(last updated July 12, 2014)
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, then change to PDF writer sCurrentPrinter = Application.ActivePrinter Application.ActivePrinter = sPDFwriter ' print document, then go back to the original printer ActiveDocument.PrintOut Application.ActivePrinter = sCurrentPrinter ' continue with the rest of your macro End Sub
WordTips is your source for cost-effective Microsoft Word training. (Microsoft Word is the most popular word processing software in the world.) This tip (318) applies to Microsoft Word 97, 2000, 2002, and 2003. You can find a version of this tip for the ribbon interface of Word (Word 2007 and later) here: Temporarily Changing the Printer in a Macro.
Comprehensive VBA Guide Visual Basic for Applications (VBA) is the language used for writing macros in all Office programs. This complete guide shows both professionals and novices how to master VBA in order to customize the entire Office suite for their needs. Check out Mastering VBA for Office 2010 today!
Not satisfied with the detail provided by the Word Count feature in Word? Perhaps you want to actually know where every ...Discover More
There may be times when you want your macro to print out a list of styles in the document. If so, then you can do it with ...Discover More
Writing macros often involves selecting different parts of your document so that some sort of processing can be ...Discover More
FREE SERVICE: Get tips like this every week in WordTips, a free productivity newsletter. Enter your address and click "Subscribe."
Got a version of Word that uses the menu interface (Word 97, Word 2000, Word 2002, or Word 2003)? This site is for you! If you use a later version of Word, visit our WordTips site focusing on the ribbon interface.