Printing word template to PDF from Excel VBA

J

JbL

Hi,

I am working on a process in vba from excel that is creating both word
templates and xcl workbooks and printing them into pdf format. I haven't had
a problem sending any of the xcl stuff to the "Acrobat Distiller" as my
printer and getting those PDF files.

It's the Word part that is now giving me issues. I have a word template
called cover_lnd.dot that I fill with the appropriate info, but when I go to
print it to the distiller my code gives me a run-time error 5121.

The problem is that is only runs smoothly if I change the Flename:=PsFile to
Filename = "" where I get prompted for the path and file of the pdf doc. The
PsFile variable is a valid path and filename so why do I get the error and
how can I get around it??

'====================================
set mypdf = new pdfdistiller

psfile = savedir & sector & "_cvr.ps"
pdfile = savedir & sector & "_cvr.pdf"

cvrpage.application.activeprinter = "Acrobat Distiller"

CvrPage.Application.PrintOut Filename:=PSFile, _
Range:=wdPrintAllDocument, _
Item:=wdPrintDocumentContent, _
Copies:=1, _
Pages:="", _
PageType:=wdPrintAllPages, _
ManualDuplexPrint:=False, _
Collate:=True, _
Background:=True, _
PrintToFile:=False, _
PrintZoomColumn:=0, _
PrintZoomRow:=0, _
PrintZoomPaperWidth:=0, _
PrintZoomPaperHeight:=0

myPDF.FileToPDF PSFile, PDFile, ""
Kill PSFile
'======================================

Thank you for your assistance!

jbl
 

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