Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Excel 2007 VBA save as PDF 1

Status
Not open for further replies.

dmuroff

MIS
Aug 15, 2004
143
CA
I'm looking to find the VBA code required to save as PDF in Excel 2007 using the Microsoft add-in.

I've been able to acheive this in Access like this:

Code:
DoCmd.OutputTo acOutputReport, "ReportName", acFormatPDF, Directory

Does Excel 2007 have a File format simliar to "acFormatPDF"?

I've tried this:
Code:
ActiveWorkbook.SaveAs "Report", xlFormatPDF
but it does not work (Runtime error 1004)

Any help would be greatly appreciated. Thanking you in advance

Dan
 
Have a look at the ExportAsFixedFormat method.

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
ExportAsFixedFormat does indeed work!

Code:
ActiveWorkbook.ExportAsFixedFormat xlTypePDF, directory

One more thing: Is it possible to use with on just the selected worksheets? i.e. something like this:

Code:
Sheets(Array("Sheet1", "Sheet2", "Sheet3", "Sheet4")).Select
Sheets("Sheet1").Activate
selection.ExportAsFixedFormat xlTypePDF, directory

The output of this code is a blank pdf
 
I'd create a temporary workbook ...

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
That did the trick!

Code:
Sheets(Array("Sheet1", "Sheet2", "Sheet3", "Sheet4")).Select
    Sheets("Sheet1").Activate
   Sheets(Array("Sheet1", "Sheet2", "Sheet3", "Sheet4")).Copy
    Sheets(Array("Sheet1", "Sheet2", "Sheet3", "Sheet4")).Select
     Sheets("Sheet1").Activate
    Selection.Copy
    Selection.PasteSpecial Paste:=xlValues, Operation:=xlNone, SkipBlanks:= _
        False, Transpose:=False
    Application.CutCopyMode = False
   DisplayAlerts = False
    ActiveWorkbook.ExportAsFixedFormat xlTypePDF, directory
    ActiveWorkbook.Close False

Thanks for the help PHV!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top