Solved

Excel 2013 macro to target specific printer

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

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

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

Suggested Solutions

Convert between Excel file formats (.XLS, .XLSX, .XLSM) with/without macro option David Miller (dlmille) Intro Over this past Fall, I've had the opportunity to see several similar requests and have developed a couple related solutions associate…
A theme is a collection of property settings that allow you to define the look of pages and controls, and then apply the look consistently across pages in an application. Themes can be made up of a set of elements: skins, style sheets, images, and o…
This Micro Tutorial will demonstrate on a Mac how to change the sort order for chart legend values and decrpyt the intimidating chart menu.
This Micro Tutorial will demonstrate in Microsoft Excel how to add style and sexy appeal to horizontal bar charts.

785 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