XL to PDF using PDFCreator syntax error


T

Trish Smith

Hi everyone,

I'm using Excel 2003, Windows XP, PDFCreator 0.9.1, GPLGhostscript.exe
download package and the following code from http://www.excelguru.ca/node/21.
I've also got PDFCreator checked in the reference library.
The line it bugs out on is outlined ************

Sub PrintToPDF_MultiSheet_Early()
'Author : Ken Puls (www.excelguru.ca)
'Macro Purpose: Print to PDF file using PDFCreator
' (Download from http://sourceforge.net/projects/pdfcreator/)
' Designed for early bind, set reference to PDFCreator

Dim pdfjob As PDFCreator.clsPDFCreator
Dim sPDFName As String
Dim sPDFPath As String
Dim lSheet As Long

Set pdfjob = New PDFCreator.clsPDFCreator
sPDFPath = ActiveWorkbook.Path & Application.PathSeparator

If pdfjob.cStart("/NoProcessingAtStartup") = False Then
MsgBox "Can't initialize PDFCreator.", vbCritical + _
vbOKOnly, "PrtPDFCreator"
Exit Sub
End If

For lSheet = 1 To ActiveWorkbook.Sheets.Count
'Check if worksheet is empty and skip if so
If Not IsEmpty(ActiveSheet.UsedRange) Then
With pdfjob
'/// Change the output file name here! ///
sPDFName = "testPDF" & Sheets(lSheet).Name & ".pdf"
.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
Worksheets(lSheet).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
End If
Next lSheet
pdfjob.cClose
Set pdfjob = Nothing
End Sub

If anyone could help me that would be brilliant! Please bear in mind that I
am a beginner:)

Cheers
 
Ad

Advertisements

J

Jim Cone

Ok, I will take a stab at it. The two printer lines should be one line...

Worksheets(lSheet).PrintOut copies:=1, ActivePrinter:="ÂPDFCreator"

The strange character, at the end of the line should be removed..."Â"
Also, you should confirm that the printer name is actually what is shown
between the quote marks.
--
Jim Cone
Portland, Oregon USA



"Trish Smith"
wrote in message
Hi everyone,
I'm using Excel 2003, Windows XP, PDFCreator 0.9.1, GPLGhostscript.exe
download package and the following code from http://www.excelguru.ca/node/21.
I've also got PDFCreator checked in the reference library.
The line it bugs out on is outlined ************

Sub PrintToPDF_MultiSheet_Early()
'Author : Ken Puls (www.excelguru.ca)
'Macro Purpose: Print to PDF file using PDFCreator
' (Download from http://sourceforge.net/projects/pdfcreator/)
' Designed for early bind, set reference to PDFCreator

Dim pdfjob As PDFCreator.clsPDFCreator
Dim sPDFName As String
Dim sPDFPath As String
Dim lSheet As Long

Set pdfjob = New PDFCreator.clsPDFCreator
sPDFPath = ActiveWorkbook.Path & Application.PathSeparator

If pdfjob.cStart("/NoProcessingAtStartup") = False Then
MsgBox "Can't initialize PDFCreator.", vbCritical + _
vbOKOnly, "PrtPDFCreator"
Exit Sub
End If

For lSheet = 1 To ActiveWorkbook.Sheets.Count
'Check if worksheet is empty and skip if so
If Not IsEmpty(ActiveSheet.UsedRange) Then
With pdfjob
'/// Change the output file name here! ///
sPDFName = "testPDF" & Sheets(lSheet).Name & ".pdf"
.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
Worksheets(lSheet).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
End If
Next lSheet
pdfjob.cClose
Set pdfjob = Nothing
End Sub

If anyone could help me that would be brilliant! Please bear in mind that I
am a beginner:)

Cheers
 
Ad

Advertisements


Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top