Solved

Excel 2013 macro to target specific printer

Posted on 2015-01-04
2
559 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 500 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

PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

Question has a verified solution.

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

How to get Spreadsheet Compare 2016 working with the 64 bit version of Office 2016
This article describes a serious pitfall that can happen when deleting shapes using VBA.
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 …
This Micro Tutorial will demonstrate how to use a scrolling table in Microsoft Excel using the INDEX function.

617 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