Hi,
I am combining several documents into 1 and, for those documents that are pdf, the Adobe (whichever Adobe tool is selected to read pdf) icon is opened for each one of them and, if I do not close it, will tell me that it is waiting for an OLE a. I need to manually close it so it can go to the next file to combine.
Is there a work around to it? (see code below, the stop is at the cPrintFile line).
'Set all defaults
With pdfjob
.cOption("UseAutosave") = 1
.cOption("UseAutosaveDirectory") = 1
.cOption("AutosaveDirectory") = sLocalAntennaPath
.cOption("AutosaveFilename") = "Temp.pdf"
.cOption("AutosaveFormat") = 0 ' 0 = PDF
.cClearCache
.cPrinterStop = True
End With
lTtlSheets = Application.Sheets.Count
lSheet = iSheetsStart - 1
Do
lSheet = lSheet + 1
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"
iNumberOfTabs = iNumberOfTabs + 1
Else
lTtlSheets = lTtlSheets - 1
End If
On Error GoTo 0
Loop Until Workbooks(ThisWorkbook.Name).Sheets(lSheet).Name = gwAntennaHeader
' Initialize the number of page to the number of tabs already generated.
nNumPage = iNumberOfTabs
' Add the Antenna files
lLine = 25
While Not IsEmpty(Workbooks(ThisWorkbook.Name).Worksheets("Main").Cells(lLine, 12).Value)
If Workbooks(ThisWorkbook.Name).Worksheets("Main").Cells(lLine, 12).Value <> sNotFound Then
lFilename = Format(Workbooks(ThisWorkbook.Name).Worksheets("Main").Cells(lLine, 9).Value) & ".pdf"
nNumPage = nNumPage + Workbooks(ThisWorkbook.Name).Worksheets("Main").Cells(lLine, 13).Value
' Get the file from the local folder (beed download before)
pdfjob.cPrintFile sLocalAntennaPath & lFilename
iNumberOfTabs = iNumberOfTabs + 1
End If
lLine = lLine + 1
Wend
'Wait until all print jobs have entered the print queue
Do Until pdfjob.cCountOfPrintjobs = iNumberOfTabs
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