PDA

View Full Version : Save new document as PDF automatically



Tricia
06-28-2004, 07:29 AM
I have a macro that creates and saves new word documents from a master file. I would like these new documents to be saved as PDF files not word. I do have adobe writer. Any suggestions?

Kelly
06-29-2004, 03:24 PM
http://www.google.com/search?q=%22converting+doc+to+pdf%22


You may wish to click the above link for some info on conversions between doc and pdf.


I have not ever dealt with the issue you raise here. However, I might be able to suggest something if I knew a little bit more information....
:call:
1. what exactly do the documents to be saved look like? :eek: are they big? small? lots of fonts and formatting? little formatting? tables? columns? headers/footers?

2. when you say that the files (how many?) are generated from a master file, does that mean that the one single master file is broken into smaller bits which then become separate files? or are there many master files?:drunkard:

3. currently, after you run your macro and the documents are saved as DOC files, do you then do something manually to make them into PDFs? If so, what do you do? or are you just leaving them as DOCs for now?

Tricia
06-30-2004, 06:06 AM
The documents are EFT Advices. One file prints out of our accounting system. I then break each advice into its own file (2 pages) so I can e-mail to the employee. Currently I am opening each file individually to print it to a pdf. Very painful since it can be over 100 files.

Kelly
06-30-2004, 07:31 AM
Okay, another question. (sorry!)

I just ran a search on "print to pdf," because I don't think I have that capability on my computer and I wanted to learn more about it.

Well, a search for "print to pdf" brings up a lot of information for Macintosh users. Are using a Macintosh?

If not, then did you download or purchase some type of utility to give you the capability to "print to pdf" ??

If so, I would be interested to download it myself so I could experiment...

Tricia
06-30-2004, 09:38 AM
I am not workin on Mac. We have adobe software which allows you to convert any file to a pdf

JOrzech
07-01-2004, 12:41 PM
Are all the documents in one folder? If so, we could give you a macro that loops through each file in a folder, prints it to PDF (it's just a driver), saves it, and closes it. Would that work for you?

Tricia
07-01-2004, 01:10 PM
Yes that would work! All the files are in the same folder.

JOrzech
07-01-2004, 02:57 PM
:yes OK Tricia - here's the macro. However, there are a couple settings in Adobe you will need to change before it works properly. I assume you don't want to name all the files, just keep the same name. I also assume you don't want Adobe to launch every time you create a new PDF from this macro. So these settings will need to be changed first:

1. Choose Start > Settings > Printers [and Faxes].
2. Right-click the Acrobat Distiller printer, and choose Printing Preferences (Windows XP or 2000), Document Defaults (Windows NT), or Properties (Windows Me or 98).
3. Click the Adobe PDF Settings tab.
4. Deselect Prompt for the PDF Filename, and then click OK.
5. Deselect View Adobe PDF results.


Then, you will need to put this code into your normal.dot. At a blank screen, press Alt F11, View, Project Explorer. Click on normal. Click on Modules. Insert, Module and paste the following code:

Sub PrintPDF()
Dim Folder As String
Dim strFileName As String
Dim doc As Document
Dim DocPath As String
DocPath = ("C:\Test\") ' change folder name here
strFileName = Dir$("C:\Test\" & "\*.doc") 'Change your folder name here
Do Until strFileName = ""
'Change your folder name here
Set doc = Application.Documents.Open("C:\Test\" & "\" & strFileName)
ActivePrinter = "Adobe PDF"
ActiveDocument.PrintOut
doc.SaveAs "C:\Test\" & strFileName & ".pdf" 'change folder name here
doc.Close
strFileName = Dir$()
Loop
End Sub

Click File, Save normal.
Press Alt F11.

At a blank document, press Alt F8 (or create a button on the toolbar if you'd like). Type or browse to PrintPDF. Hit Run.

Hope that works for you.

JOrzech
07-04-2004, 12:58 PM
A free print to PDF Utility is built into OpenOffice.org.
http://www.openoffice.org/

If you open their word processor, and click File, you have the ability to print to PDF. It comes free with the program. Although I've not used it myself, my nephew downloaded the program just to have that ability without buying from Adobe. He loves it....

JOrzech
07-10-2004, 07:29 AM
Tricia - did any of my suggestions work for you?

lucas
07-10-2004, 09:11 AM
Joanne,
I have a pdf print driver on my computer and this code works for me with a few minor problems.
it creates and extra file:
PrintPDF.doc.pdf which is corrupt

the original filename is:

PrintPDF.doc

as well as the PrintPDF.pdf

also, it closes the original word file without closing the program. I will make a few changes and let you know. Here is the code I got from you with the path and driver changed and it works with the stipulations listed above.

Sub PrintPDF()
Dim Folder As String
Dim strFileName As String
Dim doc As Document
Dim DocPath As String
DocPath = ("C:\Temp\") ' change folder name here
strFileName = Dir$("C:\Temp\" & "\*.doc") 'Change your folder name here
Do Until strFileName = ""
'Change your folder name here
Set doc = Application.Documents.Open("C:\Temp\" & "\" & strFileName)
ActivePrinter = "Acrobat PDFWriter"
ActiveDocument.PrintOut
doc.SaveAs "C:\Temp\" & strFileName & ".pdf" 'change folder name here
doc.Close
strFileName = Dir$()
Loop
End Sub


Steve

lucas
07-10-2004, 09:40 AM
Joanne and Tricia,

I took one line of code out of your routine and it works fine. You just can't have the file that you are running the script from in the directory you are working on. For example, in this script I am working on files in C:\Temp

Your doc file with the script must be in a different directory. Also you will have to try to print a file to find the name of your acrobat print driver. Just try to print some thing and drop the box to select printers and use the name in the box that refers to the acrobat printer.

Here is the script as I have it working. One other thing, it works on multple files in the c:\temp directory. I have tried it. You just have to click to save each pdf file.


Sub PrintPDF()
Dim Folder As String
Dim strFileName As String
Dim doc As Document
Dim DocPath As String
DocPath = ("C:\Temp\") ' change folder name here
strFileName = Dir$("C:\Temp\" & "\*.doc") 'Change your folder name here
Do Until strFileName = ""
'Change your folder name here
Set doc = Application.Documents.Open("C:\Temp\" & "\" & strFileName)
ActivePrinter = "Acrobat PDFWriter"
ActiveDocument.PrintOut
doc.Close
strFileName = Dir$()
Loop
End Sub

Let me know if this helps,
Steve

JOrzech
07-10-2004, 10:16 AM
Funny - I didn't have a problem with it... but maybe because I have the Adobe Professional version.

Why do you have to click to save each PDF version? That's what you must disable in my original post. Clarify please. Many thanks Steve.

lucas
07-10-2004, 11:11 AM
Joanne,
Yes, the line I removed was to save the pdf file:

doc.SaveAs "C:\Temp\" & strFileName & ".pdf" 'change folder name here


And I don't have the professional version. Thats probably why I ran into the problem I had. I just have a pdf print driver that was installed with some graphics software that I have had for a while.

Could also be that the file with the macro needs to be in a different directory. Did you find that to be true?

hope this helps,
Steve

JOrzech
07-10-2004, 11:17 AM
Thanks Steve but I did not find it necessary to save to a different folder at all. Perhaps it does have something to do with the various versions of Adobe. But all my PDFs wrote to the same folder as the docs were in. Albeit, they did have the *.doc.pdf extension.

If you could fix that, it would be awesome!

lucas
07-10-2004, 12:16 PM
Joanne,
I have a few things going on but will look at this asap. I think we can do it but looks like we need to use myDocname instead of strFileName. If anyone has any better ideas they would be welcome.
Steve

lucas
07-10-2004, 10:39 PM
Joanne,
I have to ask this because the line in the code that reads:
doc.SaveAs "C:\Temp\" & strFileName & ".pdf"
strikes me as being code for saving a doc file with a pdf file extention.(In other words, saveas a word doc file and add the pdf extention to that)
When it creates the files with the filename.doc.pdf file extention and I try to open them with acrobat, I get an error. If I remove the pdf file extention from the files created with the code and try to open it as simply filename.doc it opens in word which seems to back up my late night assumption.

Please let me know if you have tried to open any of the files you have created with this code.
Steve

JOrzech
07-11-2004, 05:59 AM
You're absolutely right Steve. Thanks for the pointing out the error of my ways:)

markvenis
11-25-2005, 03:28 AM
Have tried using this code and works but have the problem of files saving as .doc.pdf, apologies if this is a dumb question but is there a way that the files can be saved so that they open in .pdf?

markvenis
11-25-2005, 03:36 AM
Have changed the code so it doesn't have the .doc extension but Adobe still won't open as says the file 'is not a supported file type or because the file has been corrupted'.