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

Picking a Chart Type

Microsoft Chart offers several different types of charts you can use to display your data. Here's how to pick the type ...

Discover More

Can't Use Hyperlinks

Before some features in Excel can function properly, you must have the correct permissions set for the user of the ...

Discover More

Shortcut for Show/Hide

Hate to take your hands off the keyboard? Here's a handy keyboard shortcut you can use to display (or not display) the ...

Discover More

Do More in Less Time! Are you ready to harness the full power of Word 2013 to create professional documents? In this comprehensive guide you'll learn the skills and techniques for efficiently building the documents you need for your professional and your personal life. Check out Word 2013 In Depth today!

More WordTips (ribbon)

Controlling the Bold Text Attribute

When processing a document in a macro, you may need to make some of your text bold. It's easy to do using the Bold ...

Discover More

Understanding the While...Wend Structure

One of the basic programming structures used in VBA is the While ... Wend structure. This structure helps to make the ...

Discover More

Determining How Many Windows are Open

You can open multiple documents at the same time in Word, and each document occupies its own document window. Here's a ...

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 two more than 7?

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.