Solved

VBA in Excel - Change Active Printer

Posted on 2013-06-09
4
2,555 Views
Last Modified: 2013-07-08
I have an excel sheet that I has a button that when clicked should print the print area as a PDF (or save as instead, but I have the print part working) and then show me a Print Preview of the same page so that I can review and optionally click "print" and send it to a physical printer.  However, the print to PDF is changing the active printer to the PDF now forcing me to change it back manually every time - this is unacceptable.

I would have thought there was a fairly easy way to tell Excel "on the next print attempt (Or more specifically, PRINT PREVIEW), use this printer"

I might be able to debug from other code and figure it out but I'm apparently experiencing logic/google foo problems and cannot come up with a timely answer.

So, without ACTUALLY initiating the printing, how to I set the excel sheet to target a specific printer the next time I print (I keep getting Run-time error '1004': Method 'ActivePrinter' of object '_Global' failed when I attempt to change it with what would seem the obvious answer ActivePrinter = "\\server\PrinterShare"
0
Comment
Question by:Lee W, MVP
4 Comments
 
LVL 50

Expert Comment

by:Rgonzo1971
ID: 39233862
Hi,

Could you try
Application.Dialogs(xlDialogPrinterSetup).Show
yourPrinter= Application.ActivePrinter

Open in new window


To determine the correct name of the printer you want

Regards
0
 
LVL 85

Accepted Solution

by:
Rory Archibald earned 500 total points
ID: 39234256
If you want to send it to the same printer that was selected before your code printed to PDF, you can store that information prior to printing
Dim sCurrentPrinter as string
sCurrentPrinter = application.activeprinter
' your code to print to pdf goes here

' reset printer
application.activeprinter = sCurrentPrinter

Open in new window


The reason your code above failed is that the printer string needs to have information about the printer port on the end - so it should always end in something like " on NE01"
0
 
LVL 46

Expert Comment

by:Martin Liss
ID: 39306582
This question has been classified as abandoned and is closed as part of the Cleanup Program. See the recommendation for more details.
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
Workbook link problems after copying tabs to a new workbook? David Miller (dlmille) Intro Have you either copied sheets to a new workbook, and after having saved and opened that workbook, you find that there are links back to the original sou…
This Micro Tutorial demonstrates how to create Excel charts: column, area, line, bar, and scatter charts. Formatting tips are provided as well.
This Micro Tutorial will demonstrate the scrolling table in Microsoft Excel using the INDEX function.

789 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question