1

I have a macro that creates individual PDFs for a set of tabs. Is there a way to add a step and combine all the PDFs into one file?

    Sub Print_Exhibit()
    Dim Numb_Exhibit As Double
    Dim File_Location As String
    Dim Sheet_Name As String
    Dim X As Double
    Dim Y As Double

    Numb_Exhibit = WorksheetFunction.Max(Sheets("Control - Exhibit 
    Key").Range("B:B"))
    File_Location = Sheets("Control - Exhibit Key").Range("K6").Value

    For X = 1 To Numb_Exhibit

    Y = 8 + X
    Sheet_Name = Sheets("Control - Exhibit Key").Range("E" & Y).Value
    Sheets(Sheet_Name).Select

    ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, filename:=File_Location 
    & "\" & Sheet_Name & ".pdf" _
    , Quality:=xlQualityStandard, IncludeDocProperties:=True, 
    IgnorePrintAreas _
    :=False, OpenAfterPublish:=True

    Next

    End Sub

Thank you so much for your help!

YowE3K
  • 23,852
  • 7
  • 26
  • 40
Wendi
  • 23
  • 5
  • 3
    https://stackoverflow.com/questions/14404650/save-multiple-sheets-to-pdf/14407986#14407986 – Tim Williams Sep 29 '17 at 22:00
  • Possible duplicate of [Save multiple sheets to .pdf](https://stackoverflow.com/questions/14404650/save-multiple-sheets-to-pdf) – TotsieMae Sep 29 '17 at 22:34
  • 1
    `ActiveWorkbook.ExportAsFixedFormat ...` exports all tabs – jsotola Sep 29 '17 at 22:36
  • If I "print to PDF" twice, this macro only allows one PDF to save over the other. Is there a way to modify this macro to allow v1, v2, v3 etc? – Wendi Oct 04 '17 at 18:38

2 Answers2

0

Loop through all tabs, copy and paste into a new common tab. Export it.

0

Did you do a prerequisite Google search before posting here?

Save multiple sheets to .pdf

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:=True
End Sub

Private 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

OR

ThisWorkbook.Sheets(Array("Sheet1", "Sheet2")).Select

ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, Filename:= _
    "C:\tempo.pdf", Quality:= xlQualityStandard, IncludeDocProperties:=True, _
     IgnorePrintAreas:=False, OpenAfterPublish:=True

ALSO

https://danwagner.co/how-do-i-save-multiple-sheets-as-a-single-pdf/

ASH
  • 20,759
  • 19
  • 87
  • 200