Solved

VBA in Excel - Change Active Printer

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

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 45

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

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

Introduction This Article briefly covers methods of calculating the NPV and IRR variants in Excel as well as the limitations in calculating and interpreting IRR results. Paraphrasing Richard Shockley, author of my favourite finance reference tex…
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…
The viewer will learn how to use the =DISCRINV command to create a discrete random variable, use this command to model a set of probabilities and outcomes in a Monte Carlo simulation, and learn how to find the standard deviation of a set of probabil…
The viewer will learn how to create two correlated normally distributed random variables in Excel, use a normal distribution to simulate the return on different levels of investment in each of the two funds over a period of ten years, and, create a …

707 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now