Please Note: This article is written for users of the following Microsoft Word versions: 2007 and 2010. If you are using an earlier version (Word 2003 or earlier), this tip may not work for you. For a version of this tip written specifically for earlier versions of Word, click here: Temporarily Changing the Printer in a Macro.

Temporarily Changing the Printer in a Macro

by Allen Wyatt
(last updated January 27, 2014)

2

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 (9808) applies to Microsoft Word 2007 and 2010. You can find a version of this tip for the older menu interface of Word here: Temporarily Changing the Printer in a Macro.

Author Bio

Allen Wyatt

With more than 50 non-fiction books and numerous magazine articles to his credit, Allen Wyatt is an internationally recognized author. He  is president of Sharon Parq Associates, a computer and publishing services company. ...

MORE FROM ALLEN

Reveal Codes in Word

While there are no true Reveal Codes in Word, as in WordPerfect, as they are vastly different word processors, there is a ...

Discover More

Incrementing Numeric Portions of Serial Numbers

If you use serial numbers that include both letters and numbers, you might wonder how you can increment the numeric portion ...

Discover More

Selecting Multiple Cells by Mistake

Click on a cell and you expect the single cell to be selected. If you instead get a group of cells, it can be frustrating to ...

Discover More

Learning Made Easy! Quickly teach yourself how to format, publish, and share your content using Word 2013. With Step by Step, you set the pace, building and practicing the skills you need, just when you need them! Check out Microsoft Word 2013 Step by Step today!

MORE WORDTIPS (RIBBON)

Moving the Insertion Point in a Macro

One of the common things done in macros is to somehow "process" documents, which often means moving the insertion point in ...

Discover More

Changing Directories in a Macro

When a macro works with files, it often has to change between different directories on your disk drive. This is done using ...

Discover More

Defining a Shortcut for a Macro

You can make running macros very easy if you assign a shortcut key to the macro. This tip demonstrates how easy it is to ...

Discover More
Subscribe

FREE SERVICE: Get tips like this every week in WordTips, a free productivity newsletter. Enter your address and click "Subscribe."

View most recent newsletter.

Comments for this tip:

If you would like to add an image to your comment (not an avatar, but an image to help in making the point of your comment), include the characters [{fig}] in your comment text. You’ll be prompted to upload your image when you submit the comment. Images larger than 600px wide or 1000px tall will be reduced. Up to three images may be included in a comment. All images are subject to review. Commenting privileges may be curtailed if inappropriate images are posted.

What is 9 - 7?

2015-02-16 16:01:00

Diana

I've been using a macro like this for years with no problems on Word 2007 and 2010. I recently tried implementing it with Word 2013, but the program crashes. I had to remark out the command line that resets the ActivePrinter. Has anyone been successful with this macro on Word 2013? Any suggestions?

This is the error info I get:
Problem signature:
Problem Event Name: BEX
Application Name: WINWORD.EXE
Application Version: 15.0.4673.1000
Application Timestamp: 54588338
Fault Module Name: unknown
Fault Module Version: 0.0.0.0
Fault Module Timestamp: 00000000
Exception Offset: e850ffff
Exception Code: c0000005
Exception Data: 00000008
OS Version: 6.1.7601.2.1.0.256.48
Locale ID: 1033

Additional information about the problem:
LCID: 1033
skulcid: 1033


2013-12-05 12:19:18

Morris Manning

Good tip!

I often need to switch printers. The easy way for users to do this from a print macro is to insert a line to bring up PrintPreview dialog. Selecting Print brings up list of installed printers including pdf if installed on computer.
Add after settings:
ActiveWindow.SelectedSheets.PrintPreview


This Site

Got a version of Word that uses the ribbon interface (Word 2007 or later)? This site is for you! If you use an earlier version of Word, visit our WordTips site focusing on the menu interface.

Newest Tips
Subscribe

FREE SERVICE: Get tips like this every week in WordTips, a free productivity newsletter. Enter your address and click "Subscribe."

(Your e-mail address is not shared with anyone, ever.)

View the most recent newsletter.

Links and Sharing