Solved

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

Posted on 2014-04-02
4
2,879 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
[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
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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Excel can be a tricky bit of software to get your head around. Whilst you’ll be able to eventually get to grips with the basic understanding of how to get by, there are a few Excel tips that not everybody will even know about let alone know how to d…
You need to know the location of the Office templates folder, so that when you create new templates, they are saved to that location, and thus are available for selection when creating new documents.  The steps to find the Templates folder path are …
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.
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

707 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