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

Determining Winners, by Category

Do you need to determine the top three values in a range of columns? The techniques discussed in this tip will come in ...

Discover More

Using R1C1 Formula References in a Macro

Besides the regular way of displaying formulas, Excel can also display them using what is called R1C1 format. If you are ...

Discover More

Where Are Templates Stored?

Need to know where templates are located in Word 2007? The locations may be the same as in earlier versions of the ...

Discover More

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!

More WordTips (menu)

Intelligible Names for Macros

The names you use for macros can affect what you see when you add those macros to a toolbar. This tip explains how you ...

Discover More

Repaginating Your Document in a Macro

When processing a document with a macro, you may need to have the macro repaginate the text. It's easy to do using the ...

Discover More

Setting a VBA Variable From a Bookmark

Bookmarks are quite helpful in a document. You may want to transfer the contents of a bookmark into a macro variable in ...

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 nine minus 5?

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.