Link to home
Start Free TrialLog in
Avatar of Fritz Paul
Fritz PaulFlag for South Africa

asked on

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

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.
ASKER CERTIFIED SOLUTION
Avatar of rspahitz
rspahitz
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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

Avatar of Joe Howard
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)
Avatar of Fritz Paul

ASKER

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.