Solved

VBA in Excel - Change Active Printer

Posted on 2013-06-09
4
2,634 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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 47

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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

This code takes an Excel list of URL’s and adds a header titled “URL List”. It then searches through all URL’s in column “A”, looking for duplicates. When a duplicate is found, it is moved to the top of the list. The duplicate URL’s are then highlig…
This article descibes how to create a connection between Excel and SAP and how to move data from Excel to SAP or the other way around.
Graphs within dashboards are meant to be dynamic, representing data from a period of time that will change each time the dashboard is updated with new data. Rather than update each graph to point to a different set within a static set of data, t…
This Micro Tutorial will demonstrate how to create pivot charts out of a data set. I also added a drop-down menu which allows to choose from different categories in the data set and the chart will automatically update.

740 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