Solved

Excel 2013 macro to target specific printer

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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Introduction This Article is a follow-up to my Mappit! Addin Article (http://www.experts-exchange.com/A_2613.html), it was inspired by an email posting I made to EUSPRIG (http://www.eusprig.org/index.htm), I will briefly cover: 1) An overvie…
This article will guide you to convert a grid from a picture into Excel format using Microsoft OneNote and no other 3rd party application.
This Micro Tutorial demonstrates how to create Excel charts: column, area, line, bar, and scatter charts. Formatting tips are provided as well.
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…

759 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now