I have code to print out selected sheets from one workbook. Have it and it works great thanks to leahProton.
I now need to save those selected mulitple sheets as a single PDF file, so I found code to do that. (opver all problem is to spool all printing s a single job)
I can get each code to work separately, but not together.
I need some help, please!
Thanks, J
Here is my code to printout the selected sheets"
Sub report()
'----------------------------------------------------------------------------------------------------
'When this procedure is run, it will:
' select the QUOTE sheet
' count the number of "Items"
' lookup the item number on the summary sheet and copy the corresponding sheet name to the printlist array
'* added:
' it will check quote sheet row 33 for an entry, if true, then add the INDIVIDUAL PRODUCT sheet
'
' it will add the QUOTE sheet as the last sheet in the list to be printed.
'------------------------------------------------------------------------------------------------------
Dim PrintList() 'array to hold sheets to print
Dim SheetCount As Integer
Dim ItemCount As Integer 'number of non-empty cells in Item column, i.e., A17 thru A29
Dim TableRange 'data on SUMMARY sheet
Dim Item 'current cell in list of QUOTE "Items"
Dim ItemList 'the "Item" column itself
Set ItemList = Range("a17:a29")
Set TableRange = Worksheets("Summary").Range("A7:G37")
Worksheets("quote").Select
ItemCount = Application.WorksheetFunction.CountA(Range("a17:a29")) 'get the total number of items listed
ReDim PrintList(1 To ItemCount) 'size the sheet list array to hold this many sheet names
'Process the "Items" column:
'for each item, check if it has a corresponding sheet name, then,
'if so, copy the sheet name to the print list
For Each Item In ItemList
If Item.Value > " " Then '<=== note: changed the test value from "" (NULL) to " " (space)
SheetCount = SheetCount + 1
If Application.WorksheetFunction.VLookup(Item.Value, TableRange, 7) <> "" Then
PrintList(SheetCount) = Application.WorksheetFunction.VLookup(Item.Value, TableRange, 7)
Else
SheetCount = SheetCount - 1
End If
Else
Exit For
End If
Next Item
'---------------- mod ------------------------------
'The following if..then..else block will check for entries in row 33 of the quote sheet. If there are, then it will
'add the A. INDIVIDUAL PRODUCTS sheet to the list along with the QUOTE sheet; else it just adds the QUOTE sheet.
'---------------------------------------------------
If Sheets("quote").Range("E33").Value > "0.00" Then
SheetCount = SheetCount + 2
ReDim Preserve PrintList(1 To SheetCount)
PrintList(SheetCount - 1) = "A. INDIVIDUAL PRODUCTS"
PrintList(SheetCount) = "QUOTE"
Else
SheetCount = SheetCount + 1
ReDim Preserve PrintList(1 To SheetCount)
PrintList(SheetCount) = "quote"
End If
Sheets(PrintList()).Select 'select all sheets in the list
ActiveWindow.SelectedSheets.PrintOut Copies:=1 'print the sheets
Sheets("QUOTE").Select
End Sub
AND HERE IS THE CODE TO SAVE MULTIPLE SHEETS AS A SINGLE PDF FILE
Option Explicit
Sub PrintToPDF_MultiSheetToOne_Late()
'Author : Ken Puls (www.excelguru.ca)
'Macro Purpose: Print to PDF file using PDFCreator
' (Download from http://sourceforge.net/projects/pdfcreator/)
' Designed for late bind, no references req'd
Dim pdfjob As Object
Dim sPDFName As String
Dim sPDFPath As String
Dim lSheet As Long
Dim lTtlSheets As Long
'/// Change the output file name here! ///
sPDFName = "Consolidated.pdf"
sPDFPath = ActiveWorkbook.Path & Application.PathSeparator
Set pdfjob = CreateObject("PDFCreator.clsPDFCreator")
'Make sure the PDF printer can start
If pdfjob.cStart("/NoProcessingAtStartup") = False Then
MsgBox "Can't initialize PDFCreator.", vbCritical + _
vbOKOnly, "Error!"
Exit Sub
End If
'Set all defaults
With pdfjob
.cOption("UseAutosave") = 1
.cOption("UseAutosaveDirectory") = 1
.cOption("AutosaveDirectory") = sPDFPath
.cOption("AutosaveFilename") = sPDFName
.cOption("AutosaveFormat") = 0 ' 0 = PDF
.cClearCache
End With
'Print the document to PDF
lTtlSheets = Application.Sheets.Count
For lSheet = 1 To Application.Sheets.Count
On Error Resume Next 'To deal with chart sheets
If Not IsEmpty(Application.Sheets(lSheet).UsedRange) Then
Application.Sheets(lSheet).PrintOut copies:=1, ActivePrinter:="PDFCreator"
Else
lTtlSheets = lTtlSheets - 1
End If
On Error GoTo 0
Next lSheet
'Wait until all print jobs have entered the print queue
Do Until pdfjob.cCountOfPrintjobs = lTtlSheets
DoEvents
Loop
'Combine all PDFs into a single file and stop the printer
With pdfjob
.cCombineAll
.cPrinterStop = False
End With
'Wait until PDF creator is finished then release the objects
Do Until pdfjob.cCountOfPrintjobs = 0
DoEvents
Loop
pdfjob.cClose
Set pdfjob = Nothing
End Sub
Bookmarks