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.
Written by Allen Wyatt (last updated January 24, 2020)
This tip applies to Word 97, 2000, 2002, and 2003
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:
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.
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!
If you need to move the insertion point within your macro, then you'll want to note the HomeKey method, described in this ...
Discover MoreWhen using a macro to format text, you can set all sorts of attributes for paragraphs or individual characters. On ...
Discover MoreFor certain types of writing, you may want to make sure that the sentences in your document do not exceed a certain ...
Discover MoreFREE SERVICE: Get tips like this every week in WordTips, a free productivity newsletter. Enter your address and click "Subscribe."
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.
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.
Visit the WordTips channel on YouTube
FREE SERVICE: Get tips like this every week in WordTips, a free productivity newsletter. Enter your address and click "Subscribe."
Copyright © 2024 Sharon Parq Associates, Inc.
Comments