I have a procedure that prints separate PDFs for each worksheet that a user selects (by checking a command button) on a "Glossary" sheet in the same workbook. It works fine, but I would like to have these all printed to a single PDF--not separate files. Can anyone help. Thanx!
Sub Print_PDFs_Click()
'
' This macro saves sheets selected on the Glossary sheet as
PDF files in the same directory where this file is located
'
Dim RelativePath As String
Dim SheetNumber As Integer
Dim SheetName As String
'
' Open a user dialog to select the folder where the PDFs will be printed
Dim FolderName As String
With Application.FileDialog(msoFileDialogFolderPicker)
.AllowMultiSelect = False
.Show
On Error Resume Next
FolderName = .SelectedItems(1)
Err.Clear
On Error GoTo 0
End With
'
' Processes all sheets in the workbook
' NOTE: for the line below, SheetNumber = x, where x is the first sheet that is to be printed _
and ActiveWorkbook.Sheets.Count - y, where y = number of sheets at the end NOT to be printed
For SheetNumber = 5 To ActiveWorkbook.Sheets.Count - 2
Sheets(SheetNumber).Activate
'
' Only print the sheets that are checked on the Glossary sheet
' NOTE: for the line below, SheetNumber - z, where z = x (above) - 1
If Worksheets("Glossary").CheckBoxes("CheckBox" & SheetNumber - 4).Value = 1 Then
Name = FolderName & "\" & ActiveSheet.Name & ".pdf"
ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, Filename:=Name, _
Quality:=xlQualityStandard, IncludeDocProperties:=True, _
IgnorePrintAreas:=False, OpenAfterPublish:=False
End If
Next SheetNumber
'
' Activates the Glossary sheet, displays message that sheets have been printed, and opens Windows Explorer folder where newly printed PDFs are located
Sheets("Glossary").Activate
MsgBox "Sheets have been printed!"
retVal = Shell("explorer.exe " & FolderName & "\", vbNormalFocus)
'
End Sub