Solved

VBA in Excel - Change Active Printer

Posted on 2013-06-09
4
2,485 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 49

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

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

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

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 will demonstrate how to use a scrolling table in Microsoft Excel using the INDEX function.
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

776 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