VBA to Print a Word Doc.

  • Hello again!
    The last thread I found about this was dated Jan. 7th and noone answered it even though 114 viewed it. I hope I have better luck.


    What VBA code do I use to print a Word Doc. from an Excel button activated macro. the word doc. will be located in the same folder as the workbook but I have no idea of the path since this workbook (entire folder) will be e-mailed to the end users.


    Solutions or suggestions will be greatly apreciated.

  • Re: VBA to Print a Word Doc.


    Try this, change the Document reference to print & you need to set a Reference to Microsoft Word in the VB Editor Tools | References.

  • Re: VBA to Print a Word Doc.


    royUK:
    I tried the code but got a compile error User definrd type not defined with the highlite on the Dim wrdApp As Word.Application
    Any Ideas?
    What does it mean where your notes say "Assumes that the previous proceedure has been executed"?
    Thanks!

  • Re: VBA to Print a Word Doc.


    RoyUK:
    I don't know how to set the reference or what the reference means I'm pretty new to this VBA code stuff. I did insert my doc name into the Set line but other than that I ran it just as it was written. Hope you can help me through it!
    Thanks

  • Re: VBA to Print a Word Doc.


    In the VBA editor goto Tools>References...


    Scroll down and check Microsoft Word 9.0 Object Library.


    Note the 9.0 may differ depending on which version of Word you have.

    Boo!:yikes:

  • Re: VBA to Print a Word Doc.


    royUK:
    Now it opens word and I get a message box that says "Please wait while Word finishes all pending print jobs" with a cancel button. There are no jobs pending print jobs and the message box never clears. What Next?
    Thanks for your time and patients!!

  • Re: VBA to Print a Word Doc.


    Then it's an issue of some kind on my end. I'll keep working on it.
    Thank you again for your help I appreciate you taking the time to help me.

  • Re: VBA to Print a Word Doc.


    Hi Brian


    This code here open and prints the word document.

    Code
    Sub Open_print_word_Click()
    '
        intPrintJobs = Range("A24")
        aNameAndPath = Range("C25")
        Range("A3").Select
        Set appWD = CreateObject("Word.Application")
        appWD.Visible = True
        appWD.Documents.Open Filename:=aNameAndPath
        appWD.ActiveDocument.PrintOut , Copies:=intPrintJobs
    End Sub


    intPrintJobs = Range("A24") is the numbers of copies you want of the word document.
    aNameAndPath = Range("C25") is the name and path of the word document you want to print.
    If you change appWD.Visible = True to appWD.Visible = False then you don't open the document first but just print it.


    Mads

Participate now!

Don’t have an account yet? Register yourself now and be a part of our community!