Converting Word docs to pdf


G

Guest

Hello out there

I'm using the code below to (successfully) create a nice small file from a
Word doc using PDFCreator. I want to use this rather than Primo because the
pdf is the same quilaity but much smaller.

The question is: how can I modify this code to automatically take the
document name and save it as "Document name.pdf" into the folder of the
document origin without getting the prompts from PDFCreator?

Sub PDF_FILE_PRINT()
Dim printer_memory
printer_memory = Application.ActivePrinter
Word.ActivePrinter = "PDFCreator"
Word.ActiveDocument.PrintOut
ActiveDocument.Close wdDoNotSaveChanges
Word.ActivePrinter = printer_memory
Application.OnTime When:=Now + TimeValue("00:00:01"), Name:="zz_CLOSE_WORD"
End Sub
Sub zz_CLOSE_WORD()
Application.Quit wdDoNotSaveChanges
End Sub
 
Ad

Advertisements

D

Doug Robbins - Word MVP

That is something that you would probably have to set up in PDFCreator. In
Acrobat, the prompt for filename/display of the created file can be
controlled by accessing the Properties dialog of the Adobe PDF Printer.

It may be possible to do it the same way with PDFCreator, but I believe that
with PrimoPDF, you have to purchase a Developer Licence to be able to access
and control such features.

--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP
 
G

Guest

Hi Doug, thanks for that. The very cool part of PDFCreator is that you don't
need a licence to do these things (I just don't know how to in Word VB, I can
in Excel) and the file sizes are smaller. Ken Puls is an Excel MVP and he has
some code on his website for automation of Excel sheets into PDFs and it
works brilliantly. I just have a cell called "pdf.name" containing the name
that I want to save the document as, and simply execute the macro, nothing
more to do.

Perhaps if I put the code that I use in Excel here it may prompt an idea (my
difficulty is that I know NUTH-ING about Word and a reasonable amount of
Excel).

This code creates a PDF from one worksheet:
Option Explicit
Sub PDF_from_1_Worksheet() 'EARLY BINDING
Dim pdfjob As PDFCreator.clsPDFCreator
Dim sPDFName As String
Dim sPDFPath As String
Dim printer_memory
printer_memory = Application.ActivePrinter

sPDFName = Range("pdf.name").Value
sPDFPath = ActiveWorkbook.Path & Application.PathSeparator

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") = sPDFPath
.cOption("AutosaveFilename") = sPDFName
.cOption("AutosaveFormat") = 0
.cClearCache
End With

ActiveSheet.PrintOut Copies:=1, ActivePrinter:="PDFCreator"
Do Until pdfjob.cCountOfPrintjobs = 1
DoEvents
Loop
pdfjob.cPrinterStop = False

Do Until pdfjob.cCountOfPrintjobs = 0
DoEvents
Loop
pdfjob.cClose
Set pdfjob = Nothing

Application.ActivePrinter = printer_memory
End Sub
 
G

Graham Mayor

I don't have PDFCreator to check, but the Excel macro uses the PDFCreator
object library. If this is made available to Word vba (vba tools >
references) then I guess you could use the same method to print from Word.

You can get the name and path required as follows:

sPDFPath = ActiveDocument.Path & Application.PathSeparator
sPDFName = ActiveDocument.Name
intPos = InStrRev(sPDFName, ".")
sPDFName = Left(sPDFName, intPos - 1)
sPDFName = sPDFName & ".pdf"

to replace the lines

sPDFName = Range("pdf.name").Value
sPDFPath = ActiveWorkbook.Path & Application.PathSeparator

and to replace Excel commands with Word commands:

ActiveDocument.PrintOut Copies:=1, ActivePrinter:="PDFCreator"
to replace the line
ActiveSheet.PrintOut Copies:=1, ActivePrinter:="PDFCreator"

and

If Len(sPDFPath) = 0 Then Exit Sub
to replace
If IsEmpty(ActiveSheet.UsedRange) Then Exit Sub

The rest I suspect will be goverened by what the object library adds to the
feast - which I doin't have to check


--
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor - Word MVP

My web site www.gmayor.com

<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
 
G

Guest

Thanks very much for that Graham, I'll have a play around with it and link
the library. If it can work it will be great because of the advantages over
Primo (smaller size, no licence required, totally free). I'll let you know
how I get on (I'll bet I'll have another question!), regards Brett.

http://sourceforge.net/projects/pdfcreator

is where you can get PDFCreator. Check it out!
 
G

Graham Mayor

I have no great need of it (I have Acrobat 8) so you will have to do your
own tweaking ;)

--
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor - Word MVP

My web site www.gmayor.com

<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
 
Ad

Advertisements

G

Guest

Hi Graham, all that works pretty well, with a couple of modifications, but it
still comes up asking for confirmation of the file name to write to the
printer, which is ok, but it doesn't find a path to the folder that the
document came from. It just goes to whatever folder was last saved to by
PDFCreator. Yet the same code in Excel asks neither file name nor folder
name. The current code is:


Sub zz()
Dim pdfjob As PDFCreator.clsPDFCreator
Dim sPDFName As String
Dim sPDFPath As String
Dim intPos As String ' I had to insert this
Dim printer_memory
printer_memory = Application.ActivePrinter

sPDFPath = ActiveDocument.Path & Application.PathSeparator
sPDFName = ActiveDocument.Name
intPos = InStrRev(sPDFName, ".")
sPDFName = Left(sPDFName, intPos - 1)
sPDFName = sPDFName & ".pdf"

If Len(sPDFPath) = 0 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") = sPDFPath
.cOption("AutosaveFilename") = sPDFName
.cOption("AutosaveFormat") = 0
.cClearCache
End With

Word.ActivePrinter = "PDFCreator"
Word.ActiveDocument.PrintOut
'ActiveDocument.PrintOut Copies:=1, ActivePrinter:="PDFCreator" it doesn't
like this line
' Do Until pdfjob.cCountOfPrintjobs = 1 These lines cause it to loop and
it works without them
' DoEvents
' Loop
pdfjob.cPrinterStop = False

Do Until pdfjob.cCountOfPrintjobs = 0
DoEvents
Loop
pdfjob.cClose
Set pdfjob = Nothing

Application.ActivePrinter = printer_memory
End Sub
 
Ad

Advertisements

G

Graham Mayor

You are going to have to take this to the vba forum in the hope that there
is someone around who has( or is prepared to install) PDFCreator to check it
out.

--
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor - Word MVP

My web site www.gmayor.com

<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
 

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