Hi all,
I was wondering if anyone could assist me with my code. The reason I have structured it in such a way, is that I want the end user to be able to make amendments to the criteria hosted on a work sheet.
Sub PrintToPDF_Early()
Application.ScreenUpdating = False
Application.DisplayAlerts = False
Dim thisBook As String
Dim pdfjob As PDFCreator.clsPDFCreator
Dim targetPath As String
Dim targetName As String
Dim targetSheet As String
Dim targetPrint As String
Dim x As String
thisBook = ActiveWorkbook.Name
Windows(thisBook).Activate
targetPath = Range("TargetFilepath").Text
targetName = Range("TargetFilename").Text
For Each Cell In Range("SheetsToPrint")
targetSheet = Cell.Value & """"
x = x & targetSheet & ","""
Next Cell
targetPrint = Left(x, Len(x) - 2)
'Check if worksheet is empty and exit if so
If IsEmpty(ActiveSheet.UsedRange) Then Exit Sub
Set pdfjob = New PDFCreator.clsPDFCreator
With pdfjob
If .cStart("/NoProcessingAtStartup") = False Then
MsgBox "Can't initialize PDFCreator.", vbCritical + _
vbOKOnly, "PrtPDFCreator"
Exit Sub
End If
.cOption("UseAutosave") = 1
.cOption("UseAutosaveDirectory") = 1
.cOption("AutosaveDirectory") = targetPath
.cOption("AutosaveFilename") = targetName
.cOption("AutosaveFormat") = 0 ' 0 = PDF
.cClearCache
End With
MsgBox targetPrint
'Print the document to PDF
Sheets(Array(targetPrint)).PrintOut copies:=1, ActivePrinter:="PDFCreator"
'Wait until the print job has entered the print queue
Do Until pdfjob.cCountOfPrintjobs = 1
DoEvents
Loop
pdfjob.cPrinterStop = False
'Wait until PDF creator is finished then release the objects
Do Until pdfjob.cCountOfPrintjobs = 0
DoEvents
Loop
pdfjob.cClose
Set pdfjob = Nothing
End Sub
I'm having real trouble with the declaration of the "TargetPrint", there are too many quotation marks, meaning the code can't recognise.
Anyone have any idea's how I can overcome this problem?
Thanks!
Bookmarks