How to Print Multiple Excel Sheets in a Single PDF File with VBA (6 Methods)

We have an Excel workbook consisting of three worksheets. The first worksheet is Sheet 1, and the data is shown in the picture below. Sheet one for Print Multiple Excel Sheets to Single PDF File with VBAThe second worksheet is Sheet 2, and the data in this sheet is shown in the following picture. Sheet two for Print Multiple Excel Sheets to Single PDF File with VBAThe third worksheet is Sheet 3, and the data in this sheet is shown in the picture below. Sheet 3 for Print Multiple Excel Sheets to Single PDF File with VBAWe will learn to print all these Excel sheets into a PDF file with VBA.

Method 1 – Embedding VBA to Print All Sheets of an Excel Workbook in a Single PDF

Sub PrintAllSheetToPdf() For Each iSheet In ActiveWorkbook.Worksheets Worksheets(iSheet.Name).Select False Next iSheet With Application.FileDialog(msoFileDialogFolderPicker) .Show iFolder = .SelectedItems(1) & "\" End With iFile = InputBox("Enter New File Name", "PDF File Name") ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, Filename:=iFolder & iFile, Quality:=xlQualityStandard, IncludeDocProperties:=True, IgnorePrintAreas:=False, OpenAfterPublish:=True End Sub

Your code is now ready to run.

Print All Multiple Excel Sheets to Single PDF File with VBA

Select folder for Print All Multiple Excel Sheets to Single PDF File with VBA

Select name for Print All Multiple Excel Sheets to Single PDF File with VBA

All the sheets in your workbook are automatically selected (notice in the image below).

Your newly created PDF file from multiple Excel sheets will start printing. This is how you print all the sheets from the Excel workbook into a single PDF file with VBA.

VBA Code Explanation

Sub PrintAllSheetToPdf()

Name the sub-procedure of the macro.

For Each iSheet In ActiveWorkbook.Worksheets Worksheets(iSheet.Name).Select False Next iSheet

Select all worksheets in the active workbook.

With Application.FileDialog(msoFileDialogFolderPicker) .Show iFolder = .SelectedItems(1) & "\" End With

Ask for a directory to save the newly created PDF file in.

iFile = InputBox("Enter New File Name", "PDF File Name")

Ask for a name for the newly created PDF file.

ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, Filename:=iFolder & iFile, Quality:=xlQualityStandard, IncludeDocProperties:=True, IgnorePrintAreas:=False, OpenAfterPublish:=True

Save all worksheets from the active workbook as a single PDF file

End Sub

Ends the sub-procedure of the macro.

Method 2 – Implementing VBA to Print Multiple Worksheets from Selection

Steps:

Sub PrintActiveSheetToPdf() Dim msg As String Dim iFolder As String Dim iFile As String msg = "Do you want to save these worksheets to a single pdf file?" & amp & nbsp & Chr(10) For Each iSheet In ActiveWindow.SelectedSheets msg = msg & iSheet.Name & Chr(10) Next iSheet iText = MsgBox(msg, vbYesNo, "Confirm to Save as PDF. ") If iText = vbNo Then Exit Sub With Application.FileDialog(msoFileDialogFolderPicker) .Show iFolder = .SelectedItems(1) & "\" End With iFile = InputBox("Enter New File Name", "PDF File Name") ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, Filename:=iFolder & iFile, Quality:=xlQualityStandard, IncludeDocProperties:=True, IgnorePrintAreas:=False, OpenAfterPublish:=True End Sub

Print Multiple Excel Sheets to Single PDF File from selection with VBA

Select multiple sheets to Print Multiple Excel Sheets to Single PDF File with VBA

We have the newly created “Student Information (Selection)” PDF file in the “ExcelDemyfolder in Drive C, as shown below.

Print the PDF file:

Print Multiple Excel Sheets from selection to Single PDF File with VBA

Your newly created PDF file from multiple Excel sheets will start printing. This is how you print all the sheets by selection from the Excel workbook into a single PDF file with VBA.

VBA Code Explanation

Sub PrintActiveSheetToPdf()

Name the sub-procedure of the macro.

Dim msg As String Dim iFolder As String Dim iFile As String

Declare the variables.

msg = "Do you want to save these worksheets to a single pdf file?" & amp & nbsp & Chr(10) For Each iSheet In ActiveWindow.SelectedSheets msg = msg & iSheet.Name & Chr(10) Next iSheet

Select only the selected worksheets in the active workbook. Show the sheet names concatenated with a question in a MsgBox to confirm. Chr(10) is a carriage return.

iText = MsgBox(msg, vbYesNo, "Confirm to Save as PDF. ") If iText = vbNo Then Exit Sub

Execute the task according to Yes or No confirmation. If Yes, then continue with the procedure. If No, then exit the procedure.

With Application.FileDialog(msoFileDialogFolderPicker) .Show iFolder = .SelectedItems(1) & "\" End With

Ask for a directory to save the newly created PDF file in.

iFile = InputBox("Enter New File Name", "PDF File Name")

Ask for a name for the newly created PDF file.

ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, Filename:=iFolder & iFile, Quality:=xlQualityStandard, IncludeDocProperties:=True, IgnorePrintAreas:=False, OpenAfterPublish:=True

Save all worksheets from the active workbook as a single PDF file

End Sub

Ends the sub-procedure of the macro.

Method 3 – Apply VBA Macro to Print Specific Sheets into Single PDF from a Workbook

Steps:

Sub PrintSpecificSheetsToPdf() Dim iSheets As Variant iSheets = Array("Sheet1", "Sheet2") ThisWorkbook.Sheets(iSheets).PrintOut End Sub Sub PrintSpecificSheetsToPdfWithLoop() Dim iSheets() As String Dim iCount As Long ReDim iSheets(1 To ThisWorkbook.Sheets.Count) For iCount = LBound(iSheets) To UBound(iSheets) iSheets(iCount) = ThisWorkbook.Sheets(iCount).Name Next iCount ThisWorkbook.Sheets(iSheets).PrintOut End Sub

Your code is now ready to run.

Print Multiple Specific Excel Sheets to Single PDF File with VBA

See the indicated part in the following image. In that line of code, we hardcoded only the specified sheet nameSheet1 and Sheet2 – that we want to export into PDF.

Browse to Print Multiple specific Excel Sheets to Single PDF File with VBA for path selection

Selecting name for Print Multiple specific Excel Sheets to Single PDF File with VBA

selecting path for Print Multiple specific Excel Sheets to Single PDF File with VBA

Now let’s check whether the “ExcelDemyfolder that we selected as the storage of our PDF file.

To print the PDF file:

Print Multiple Specific Excel Sheets to Single PDF File with VBA

Your newly created PDF file from multiple specified Excel sheets will start printing. This is how you print the multiple specified sheets from the Excel workbook into a PDF file with VBA.

VBA Code Explanation

Sub PrintSpecificSheetsToPdf()

Name the sub-procedure of the macro.

Dim iSheets As Variant

Declare the variable to store the multiple sheets.

iSheets = Array("Sheet1", "Sheet2")

Store the sheets that will be exported in the declared array variable.

ThisWorkbook.Sheets(iSheets).PrintOut

Prints the group of sheets with the PrintOut function .

End Sub

Ends the sub-procedure of the macro.

Sub PrintSpecificSheetsToPdfWithLoop()

Name the sub-procedure of the macro that will perform the loop operation.

Dim iSheets() As String Dim iCount As Long 

Declare the variables .

ReDim iSheets(1 To ThisWorkbook.Sheets.Count)

Re-declare the array variable. This time it stores the number of the total sheet count in it.

For iCount = LBound(iSheets) To UBound(iSheets) iSheets(iCount) = ThisWorkbook.Sheets(iCount).Name Next iCount 

This part of the code starts iterating from the smallest subscript to the largest subscript of the array and stores the array value in the variable. It continues doing this until it finishes scanning through the whole array.

ThisWorkbook.Sheets(iSheets).PrintOut

Prints the group of sheets with the PrintOut function.

End Sub

Ends the sub-procedure of the macro.

Method 4 – Embedding VBA to Print Multiple Sheets as PDF and Rename According to Cell Value

Steps:

Option Explicit Public Sub PrintSpecificSheetsToPdfWithRename() Dim iSheetList As Variant Dim iSheet As Worksheet Dim iFileName As String Dim iFilePath As String Set iSheet = ThisWorkbook.Sheets("Sheet1") iSheetList = Array("Sheet1", "Sheet2") iFilePath = "C:\ExcelDemy\" With iSheet iFileName = iFilePath & .Range("B5").Value & " " & .Range("C5").Value & "-" & .Range("D5").Value & ".pdf" End With ThisWorkbook.Sheets(iSheetList).Select iSheet.ExportAsFixedFormat Type:=xlTypePDF, Filename:=iFileName, Quality:=xlQualityStandard, IncludeDocProperties:=True, IgnorePrintAreas:=False, OpenAfterPublish:=True iSheet.Select End Sub

Print Multiple Excel Sheets to Single PDF File with VBA and rename

Before running the code, do you see the indicated part in the following image?