Word Macro to print PDF

Posted on 2008-11-13
Last Modified: 2012-05-05
I need a macro to print an open document as a pdf and automatically put in the name of the output PDF to be the same as the incoming name.

It would also be good to be able to specify in the macro where the output PDF is going to be saved.

I tried to record one, but it hangs at the point where it asks what name to give it.

Application.PrintOut FileName:="", Range:=wdPrintAllDocument, Item:= _
        wdPrintDocumentContent, Copies:=1, Pages:="", PageType:=wdPrintAllPages, _
        ManualDuplexPrint:=False, Collate:=True, Background:=True, PrintToFile:= _
        False, PrintZoomColumn:=0, PrintZoomRow:=0, PrintZoomPaperWidth:=0, _
    With Options
        .UpdateFieldsAtPrint = False
        .UpdateLinksAtPrint = False
        .DefaultTray = "Use printer settings"
        .PrintBackground = True
        .PrintProperties = False
        .PrintFieldCodes = False
        .PrintComments = False
        .PrintHiddenText = False
        .PrintXMLTag = False
        .PrintDrawingObjects = True
        .PrintDraft = False
        .PrintReverse = False
        .MapPaperSize = False
        .PrintOddPagesInAscendingOrder = False
        .PrintEvenPagesInAscendingOrder = False
        .PrintBackgrounds = False
    End With
    With ActiveDocument
        .PrintPostScriptOverText = False
        .PrintFormsData = False
    End With

Question by:911bob
    LVL 37

    Expert Comment

    by:Joanne M. Orzech
    What version of Adobe are you using?  You can set it in Adobe to capture the file name and create the PDF so all you have to really do is print the file to the PDF printer....

        ActivePrinter = "Adobe PDF"

    Open in new window


    Author Comment

    That does exactly what mine does.. It brings up the dialog box asking where and what name you want to save it as.

    How do I get that to be fed in automatically so you do not have to specify the name or location?

    Name should defautl to the MS Word Doc name
    LVL 37

    Expert Comment

    by:Joanne M. Orzech
    It depends - what version of Adobe are you running?

    Author Comment

    LVL 37

    Accepted Solution

    Right click on Start, go to the Printers, right-click on Adobe PDF, go to Properties.  The first box that comes up has an option to "Prompt for Filename" - deselect that.

    See if that works.

    Author Comment

    It was actually under Printing preferences after I opened the properties dialog, but you can specify where it gets saves there.

    LVL 37

    Expert Comment

    by:Joanne M. Orzech
    Excellent!  Glad to have been of assistance.  (I'm still running Adobe 6 Professional... so ....)

    Word MVP

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Do You Know the 4 Main Threat Actor Types?

    Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

    When creating Microsoft Word-based forms there may be a need to have a form field repeated throughout the whole document. For instance, with a company name, you may want this information repeated automatically throughout the document rather than man…
    The Selection object is designed for user interaction. It has a Range property, so it can be used in most places that a Range object can. Recorded macros must use the Selection because they are simply copying what the user is doing. A Range prope…
    Learn how to make your own table of contents in Microsoft Word using paragraph styles and the automatic table of contents tool. We'll be using the paragraph styles in Word’s Home toolbar to help you create a table of contents. Type out your initial …
    This Experts Exchange video Micro Tutorial shows how to tell Microsoft Office that a word is NOT spelled correctly. Microsoft Office has a built-in, main dictionary that is shared by Office apps, including Excel, Outlook, PowerPoint, and Word. When …

    758 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    10 Experts available now in Live!

    Get 1:1 Help Now