PDF four versions of a document then delete interim saved Word files

M

Mike Starr

So I'm working on this template and the client wants it to have the ability
to make PDFs of four different versions of the same document... basically
changing the logo to reflect the different businesses that are part of the
corporation. Okay, I've got that all set up. A couple things are challenging
me, though.

1. I've got a button the user can click to generate the four different PDFs.
In order to do so, I have to give the document a different file name for
each one, otherwise when I create the PDFs it would just overwrite the same
PDF file and I'd only end up with one. So I modify the filename and do a
"Save As..." and everything's cool.

However, I'm unable to pass the path to the Acrobat Distiller printer so I
have to have the user manually browse to the directory where the PDF files
should be saved.

Anyone know of a way I can programmatically pass the appropriate path to the
Acrobat Distiller print dialog? Of course, I'd rather not have to have the
Acrobat Distiller print dialog display at all but it doesn't seem there's a
way to just have it all happen under the hood. Any pointers would be
welcome.

2. Because I'm doing the "Save As...", I'm ending up with four separate .DOC
files. When I create the file I initially save it with a compound filename,
consisting of a filename string the user provides (I put up a dialog box
requiring the user to enter a filename) with a string representing the
initial logo. So, for example, the initial file might be named
"Document1-logo1.doc". When I go through the PDF process, I modify the
filename to reflect the change of the logo and do a "Save As...", ending up
with three other files... "Document1-logo2.doc", "Document1-logo3.doc" and
"Document1-logo4.doc". So the process is as follows:

*Create "Document1-logo1.doc"
*Print "Document1-logo1.doc" to Acrobat Distiller printer, yielding the
default filename of "Document1-logo1.pdf"
*Save as "Document1-logo2.doc"
*Print "Document1-logo2.doc" to Acrobat Distiller printer, yielding the
default filename of "Document1-logo2.pdf"
*Save as "Document1-logo3.doc"
*Print "Document1-logo3.doc" to Acrobat Distiller printer, yielding the
default filename of "Document1-logo3.pdf"
*Save as "Document1-logo4.doc"
*Print "Document1-logo4.doc" to Acrobat Distiller printer, yielding the
default filename of "Document1-logo4.pdf"

The client wants the process to end up with only the original file
("Document1-logo1.doc"), so I need to delete "Document1-logo2.doc",
"Document1-logo3.doc" and "Document1-logo4.doc". I store the fully-qualified
filenames that I've used as strings named "killfile1", "killfile2" and
"killfile3" but when I attempt to delete the files using the language "kill
killfile1" I get a "Runtime error '70', Permission denied". So it appears
that I've got the instruction correct but there's something that prevents me
from actually deleting the file.

So my second question is how do I avoid the "Runtime error '70', Permission
denied"? Or is there a way I can pass the preferred PDF filename and path
directly to the Acrobat Distiller printer driver so I never have to do a
"Save As..." to the Word document??

3. When I create the file initially, the filename I use is constructed from
user input (from the example above, the user would have typed "Document1" in
the dialog box I put up) with a representative logo string ("-logo1"). If,
at some point in the future, the user wants to revise the document, they'll
open "Document1-logo1.doc". Now I have a problem because I don't have a
user-entered string stored ("Document1"). So if they then click the PDF
button, they end up with:

"Document1-logo1.doc"
"Document1-logo1.pdf"
"Document1-logo1-logo2.doc"
"Document1-logo1-logo2.pdf"
"Document1-logo1-logo3.doc"
"Document1-logo1-logo3.pdf"
"Document1-logo1-logo4.doc"
"Document1-logo1-logo4.pdf"

And my file deletion code fails because it's never able to construct the
proper "killfile1", "killfile2" and "killfile3" strings.

<arggh>

Any suggestions??

Thanks

Mike
 
J

Jezebel

In the PDF conversion settings you can specify that Acrobat not prompt for a
filename -- in which case it uses the same name as the original document
(with PDF extension), saved in the same folder. So one method is to create
the PDF, then rename it as needed.

Something like --

Dim pBaseName as string
Dim pOldName as string
Dim pNewName as string
Dim pIndex as long

'BaseName: name of document with no extension
pBaseName = Left$(ActiveDocument.FullName, len(ActiveDocument.FullName)-4)

'OldName: the default name for the PDF
pOldName = pBaseName & ".pdf"

For pIndex = 1 to 4

[Insert logo (pIndex)....]

'NewName: what the PDF should be called
pNewName = pBaseName & " - logo " & pIndex & ".pdf"
ActiveDocument.Save
[Print to PDF]
Name pOldName as pNewName

Next
 

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