Solved

Excel 2013 macro to target specific printer

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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

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…
When you see single cell contains number and text, and you have to get any date out of it seems like cracking our heads.
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.
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

856 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