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.

Temporarily Changing the Printer in a Macro

Written by Allen Wyatt (last updated January 24, 2020)
This tip applies to Word 97, 2000, 2002, and 2003


3

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:

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

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

Making Sure Cells are Filled In before Saving

When creating a workbook that will be used by others, you may wish to ensure that the user fills in some cells before ...

Discover More

Limiting Spell Checking

Spell check a document, and Word normally checks several different dictionaries. Here's how to limit the dictionary ...

Discover More

Quickly Displaying the Page Setup Dialog Box

The Page Setup dialog box is indispensable in setting up the overall look of your document. You can display the dialog ...

Discover More

Create Custom Apps with VBA! Discover how to extend the capabilities of Office 2013 (Word, Excel, PowerPoint, Outlook, and Access) with VBA programming, using it for writing macros, automating Office applications, and creating custom applications. Check out Mastering VBA for Office 2013 today!

More WordTips (menu)

Automatically Running a Macro

Word allows you to create macros that can run at special times, automatically. This tip explains five special macros that ...

Discover More

Repaginating in a Macro

When creating a macro that extensively processes a document, you may need to periodically force Word to repaginate the ...

Discover More

Running Macros from Macros

Need to run one macro from within another macro? You can easily do it by using the Run method of the Application object, ...

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?

2022-03-18 00:32:13

Malcolm Sokol

Just read the tip about temporary change to default printer to a PDF printer. This was for MS Word. My question is whether similar code works for Excel. Specifically, I would like to change the default printer so that a Userform.PrintForm command which goes to the default printer without a printer diaglog would work. Thanks. I am subscribed to your Excel tips but this tip came up doing a web search.


2016-05-18 17:46:01

CK

Here's the problem I have... When you reset to the string of whatever the original default printer was, you're not TRULY resetting to "default printer," you're specifically assigning it to a printer that, for the moment, happens to be the default printer. The problem comes in when a user changes their default printer OUTSIDE of VBA.

So say I've got a default network printer, we'll call it NetPrintA, and another printer called PdfPrint. I use VBA to grab the NetPrintA string as current printer, set activeprinter to PdfPrint, then later use VBA to set activeprinter to NetPrintA. NOW, let's say NetPrintA gets replaced with a brand new printer called NetPrintB, and in my computer's settings, I set the default printer to NetPrintB. Guess what? the activeprinter property still reads the current printer as NetPrintA.

So is there a way to use VBA to determine what the actual default printer is on your computer, rather than simply whatever is currently set to the activeprinter property?


2015-05-13 05:29:40

anon

for a network printer simply use \servernameprintersharename when setting the string value.


This Site

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.

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.