Please Note: This article is written for users of the following Microsoft Word versions: 2007, 2010, 2013, and 2016. 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

Written by Allen Wyatt (last updated June 7, 2021)
This tip applies to Word 2007, 2010, 2013, and 2016


1

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

Note, in this example, that the active printer is first saved in the sCurrentPrinter variable, and then the active printer is set to whatever is in the sPDFwriter variable. (As noted, you'll need to initialize sPDFwriter so it contains a valid printer name.) After the printing is done, then the active printer is set back to what you previously stored in the sCurrentPrinter variable.

Note:

If you would like to know how to use the macros described on this page (or on any other page on the WordTips sites), I've prepared a special page that includes helpful information. Click here to open that special page in a new browser tab.

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, 2010, 2013, and 2016. 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

Smushing Text Together

Word gives you control over how your text appears on the page. This includes adjusting how close letters are to each ...

Discover More

Excel Refuses to Put Page Breaks between Subtotal Groups

Page breaks not appearing where you expect them in your subtotaled data? It could be because of a setting you made in ...

Discover More

Modifying How Windows Notifies You of Impending Changes

Part of the security system built into Windows involves notifying you when changes are about to occur to your system. ...

Discover More

The First and Last Word on Word! Bestselling For Dummies author Dan Gookin puts his usual fun and friendly candor back to work to show you how to navigate Word 2013. Spend more time working and less time trying to figure it all out! Check out Word 2013 For Dummies today!

More WordTips (ribbon)

Understanding Functions

Do some macro programming in VBA and you'll quickly find out that you can use functions to extend the power and ...

Discover More

Swapping Two Numbers

When developing a macro, you may need to swap the values in two variables. It's simple to do using the technique in this tip.

Discover More

Converting Numbers to Text

Got some numbers you need spelled out? Here's a handy macro that can convert numbers like "123" to words like "one ...

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

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}] (all 7 characters, in the sequence shown) in your comment text. You’ll be prompted to upload your image when you submit the comment. Maximum image size is 6Mpixels. 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 1 + 1?

2018-01-12 11:39:26

Church

Im using Word 2016 and this works perfectly but only in the VBA editor window. When I run it on a document, outside the editor, it gives me a blank error window. This screenshot shows the error with your code and my code in the editor: http://take.ms/UcvR2

any help is greatly appreciated.


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.

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