?
Solved

Excel 2013 macro to target specific printer

Posted on 2015-01-04
2
Medium Priority
?
634 Views
Last Modified: 2015-01-04
I need to create a macro to print the active sheet in Excel to a specific printer. I used to be able to do this by recording a macro in earlier versions of Excel, but the macro that gets generated only goes to the active printer, not the specific printer selected in the macro recording process in Excel 2013.

I cane up with this code to note the current active printer, switch to my target printer, print the sheet then reset the active printer:

Sub PrintToPDF()
Dim UsualPrinter As String
UsualPrinter = Application.ActivePrinter
Application.ActivePrinter = "CutePDF Writer"
ActiveSheet.PrintOut
Application.ActivePrinter = UsualPrinter
End Sub


The VB code fails with:

Run-time error 1004
Method 'ActivePrinter' of object '_Application' failed.

The debugger opens up with the 4th line highlighted in yellow, i.e.:

Application.ActivePrinter = "CutePDF Writer"

The name of the printer is correct.
0
Comment
Question by:snooflehammer
[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
2 Comments
 
LVL 47

Accepted Solution

by:
Wayne Taylor (webtubbs) earned 2000 total points
ID: 40530856
The name needs to include the port the printer is installed on.

Application.ActivePrinter = "CutePDF Writer on Ne00:"

Wayne
0
 

Author Closing Comment

by:snooflehammer
ID: 40530942
Thank you.
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

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

You need to know the location of the Office templates folder, so that when you create new templates, they are saved to that location, and thus are available for selection when creating new documents.  The steps to find the Templates folder path are …
This article describes how you can use Custom Document Properties to store settings and other information in your workbook so that they will be available the next time you open the workbook.
This Micro Tutorial will demonstrate the scrolling table in Microsoft Excel using the INDEX function.
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…

718 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