Consulting

Results 1 to 20 of 20

Thread: Save new document as PDF automatically

  1. #1
    VBAX Regular
    Joined
    Jun 2004
    Posts
    14
    Location

    Save new document as PDF automatically

    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?

  2. #2
    VBAX Regular Kelly's Avatar
    Joined
    Jun 2004
    Location
    Los Angeles, California
    Posts
    84
    http://www.google.com/search?q=%22co...+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....

    1. what exactly do the documents to be saved look like? 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?

    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?

  3. #3
    VBAX Regular
    Joined
    Jun 2004
    Posts
    14
    Location
    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.

  4. #4
    VBAX Regular Kelly's Avatar
    Joined
    Jun 2004
    Location
    Los Angeles, California
    Posts
    84
    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...

  5. #5
    VBAX Regular
    Joined
    Jun 2004
    Posts
    14
    Location
    I am not workin on Mac. We have adobe software which allows you to convert any file to a pdf

  6. #6
    VBAX Regular JOrzech's Avatar
    Joined
    Jun 2004
    Location
    Upstate New York
    Posts
    83
    Location
    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?
    Joanne

  7. #7
    VBAX Regular
    Joined
    Jun 2004
    Posts
    14
    Location
    Yes that would work! All the files are in the same folder.

  8. #8
    VBAX Regular JOrzech's Avatar
    Joined
    Jun 2004
    Location
    Upstate New York
    Posts
    83
    Location
    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:

    [vba]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[/vba]

    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.
    Last edited by Anne Troy; 07-01-2004 at 03:19 PM.
    Joanne

  9. #9
    VBAX Regular JOrzech's Avatar
    Joined
    Jun 2004
    Location
    Upstate New York
    Posts
    83
    Location

    To Kelly....

    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....
    Joanne

  10. #10
    VBAX Regular JOrzech's Avatar
    Joined
    Jun 2004
    Location
    Upstate New York
    Posts
    83
    Location
    Tricia - did any of my suggestions work for you?
    Joanne

  11. #11
    Moderator VBAX Wizard lucas's Avatar
    Joined
    Jun 2004
    Location
    Tulsa, Oklahoma
    Posts
    7,323
    Location

    It works for me

    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.

    [VBA]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
    [/VBA]

    Steve

  12. #12
    Moderator VBAX Wizard lucas's Avatar
    Joined
    Jun 2004
    Location
    Tulsa, Oklahoma
    Posts
    7,323
    Location

    Got it to work

    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.

    [VBA]
    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
    [/VBA]
    Let me know if this helps,
    Steve

  13. #13
    VBAX Regular JOrzech's Avatar
    Joined
    Jun 2004
    Location
    Upstate New York
    Posts
    83
    Location
    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.
    Joanne

  14. #14
    Moderator VBAX Wizard lucas's Avatar
    Joined
    Jun 2004
    Location
    Tulsa, Oklahoma
    Posts
    7,323
    Location

    clarification

    Joanne,
    Yes, the line I removed was to save the pdf file:
    [VBA]
    doc.SaveAs "C:\Temp\" & strFileName & ".pdf" 'change folder name here

    [/VBA]
    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

  15. #15
    VBAX Regular JOrzech's Avatar
    Joined
    Jun 2004
    Location
    Upstate New York
    Posts
    83
    Location

    Further clarification...

    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!
    Joanne

  16. #16
    Moderator VBAX Wizard lucas's Avatar
    Joined
    Jun 2004
    Location
    Tulsa, Oklahoma
    Posts
    7,323
    Location

    Might be able to

    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

  17. #17
    Moderator VBAX Wizard lucas's Avatar
    Joined
    Jun 2004
    Location
    Tulsa, Oklahoma
    Posts
    7,323
    Location

    question

    Joanne,
    I have to ask this because the line in the code that reads:
    [VBA] doc.SaveAs "C:\Temp\" & strFileName & ".pdf"[/VBA]
    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

  18. #18
    VBAX Regular JOrzech's Avatar
    Joined
    Jun 2004
    Location
    Upstate New York
    Posts
    83
    Location
    You're absolutely right Steve. Thanks for the pointing out the error of my ways
    Joanne

  19. #19
    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?

  20. #20
    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'.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •