Solved

VBA to Print from Excel 2010 to pdf to a given path with a given filename.

Posted on 2014-04-02
4
2,832 Views
Last Modified: 2014-04-02
I have an Excel 2010 workbook with 9 worksheets.

7 of the worksheets each contains a report in a named range on it.

I want to print these reports either individually or preferrably together in one pdf and then save to a given directory using VBA. Before creating any pdf I will use VBA to assign a unique name to it.

I normally use PDFCreator for printing to pdf format, but I will use whatever can do my task well.

Do you have a solution please.
0
Comment
Question by:Fritz Paul
  • 2
4 Comments
 
LVL 22

Accepted Solution

by:
rspahitz earned 500 total points
ID: 39972363
It seems that the save-as PDF functionality is built into Excel.
From there, you can choose Options to get the entire workbook printed.  Not sure, but you can probably hide the 2 pages you don't want and they won't get printed.

So here's the approach I'd take:

On request (a button or other event) launch some VBA.  Have the VBA
1) request a file name
2) hide the sheets that you don't want to print
3) save-as PDF with the option for all workbooks
4) unhide the sheets

Does that sound like an approach that will work for you?

(Oh, and it seems that each sheet can have it's own print area that will ignore parts you don't want to print.)
0
 
LVL 22

Expert Comment

by:rspahitz
ID: 39972384
the core of the code is here:

   strFileName = inputbox("File path?")
    ActiveWorkbook.ExportAsFixedFormat Type:=xlTypePDF, Filename:= _
        strFileName _
        , Quality:=xlQualityStandard, IncludeDocProperties:=True, IgnorePrintAreas _
        :=False, OpenAfterPublish:=True

Open in new window

0
 
LVL 27

Expert Comment

by:MacroShadow
ID: 39972390
The work flow would be:
1. optional - Copy the named ranges to one worksheet
2. Save the worksheet/workbook as PDF (no need for third-party components)
0
 

Author Closing Comment

by:Fritz Paul
ID: 39974212
Thanks that helped a lot.
It is really convenient.
I can select all the sheets I want to print and then just go save them all together in one pdf.
I recorded a macro and that worked fine.
I will figure out the rest of the code.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Drop Down List with Unique/Distinct Values (enhancing the Combo-Box with a few steps and a little code) David miller (dlmille) Intro Have you ever created a data validation list from a database field or spreadsheet column (e.g., Zip Codes or Co…
Drop Down List with Unique/Distinct Values (Part II - ComboBox or ListBox and Data Validation List Bonus!) David Miller (dlmille) Intro This article focuses on delivering unique, sorted lists to list objects (e.g., ComboBox, ListBox) and Dat…
The view will learn how to download and install SIMTOOLS and FORMLIST into Excel, how to use SIMTOOLS to generate a Monte Carlo simulation of 30 sales calls, and how to calculate the conditional probability based on the results of the Monte Carlo …
This Micro Tutorial will demonstrate in Microsoft Excel how to add style and sexy appeal to horizontal bar charts.

867 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

12 Experts available now in Live!

Get 1:1 Help Now