Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

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

Posted on 2014-04-02
4
Medium Priority
?
2,923 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 1500 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

Ask an Anonymous Question!

Don't feel intimidated by what you don't know. Ask your question anonymously. It's easy! Learn more and upgrade.

Question has a verified solution.

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

Do you use a spreadsheet like Microsoft's Excel?  Have you ever wanted to link out to a non excel file on your computer or network drive?  This is the way I found to do it!
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 …
Graphs within dashboards are meant to be dynamic, representing data from a period of time that will change each time the dashboard is updated with new data. Rather than update each graph to point to a different set within a static set of data, t…
This Micro Tutorial demonstrates in Microsoft Excel how to consolidate your marketing data by creating an interactive charts using form controls. This creates cool drop-downs for viewers of your chart to choose from.

610 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