Save multiple sheets to .pdf Save multiple sheets to .pdf vba vba

Save multiple sheets to .pdf


Start by selecting the sheets you want to combine:

ThisWorkbook.Sheets(Array("Sheet1", "Sheet2")).SelectActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, Filename:= _    "C:\tempo.pdf", Quality:= xlQualityStandard, IncludeDocProperties:=True, _     IgnorePrintAreas:=False, OpenAfterPublish:=True


Similar to Tim's answer - but with a check for 2007 (where the PDF export is not installed by default):

Public Sub subCreatePDF()    If Not IsPDFLibraryInstalled Then        'Better show this as a userform with a proper link:        MsgBox "Please install the Addin to export to PDF. You can find it at http://www.microsoft.com/downloads/details.aspx?familyid=4d951911-3e7e-4ae6-b059-a2e79ed87041".         Exit Sub    End If    ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, _        Filename:=ActiveWorkbook.Path & Application.PathSeparator & _        ActiveSheet.Name & " für " & Range("SelectedName").Value & ".pdf", _        Quality:=xlQualityStandard, IncludeDocProperties:=True, _        IgnorePrintAreas:=False, OpenAfterPublish:=TrueEnd SubPrivate Function IsPDFLibraryInstalled() As Boolean'Credits go to Ron DeBruin (http://www.rondebruin.nl/pdf.htm)    IsPDFLibraryInstalled = _        (Dir(Environ("commonprogramfiles") & _        "\Microsoft Shared\OFFICE" & _        Format(Val(Application.Version), "00") & _        "\EXP_PDF.DLL") <> "")End Function


I recommend adding the following line after the export to PDF:

ThisWorkbook.Sheets("Sheet1").Select

(where eg. Sheet1 is the single sheet you want to be active afterwards)

Leaving multiple sheets in a selected state may cause problems executing some code. (eg. unprotect doesn't function properly when multiple sheets are actively selected.)