+ Reply to Thread
Results 1 to 3 of 3

Printing a Word doc from Excel VBA code

  1. #1
    BruceInMiami
    Guest

    Printing a Word doc from Excel VBA code

    Thanks to John Walkenbach's Excel 2003 Power Programming, I can populate a
    Word template with Excel data and save the doc file, but I can't figure out
    the code to print the document so that I don't have to reopen it.

    Can anyone help?
    Thanks,
    Bruce

  2. #2
    BruceInMiami
    Guest

    RE: Printing a Word doc from Excel VBA code

    I found the answer in a 7/19/05 reply by Henry. I guess my problem was not
    the wrdApp.PrintOut code, but that I needed to give Word time to print it
    before closing it:
    wrdApp.PrintOut
    Application.Wait Time + TimeValue("00:00:05")

    If anyone has any further comments or clarifications I would appreciate it.
    Thanks,
    Bruce

    "BruceInMiami" wrote:

    > Thanks to John Walkenbach's Excel 2003 Power Programming, I can populate a
    > Word template with Excel data and save the doc file, but I can't figure out
    > the code to print the document so that I don't have to reopen it.
    >
    > Can anyone help?
    > Thanks,
    > Bruce


  3. #3
    Dave Peterson
    Guest

    Re: Printing a Word doc from Excel VBA code

    There's an option in MSWord that you can turn off.

    Tools|Options|print tab|uncheck background printing

    Then word will wait until the print job finishes.

    A longggg time ago, (word95???), background printing caused trouble printing
    tables or shapes or something. As a habit, I always turn this option off.
    (Although, newer versions of MSWord may have been fixed.)

    In code, you could do something like:

    Option Explicit
    Sub Testme()

    Dim WDApp As Object
    Dim WDDoc As Object
    Dim myDocName As String
    Dim myPrintBackground As Boolean

    myDocName = "c:\my documents\word\doc2.doc"

    Set WDApp = CreateObject("Word.Application")
    WDApp.Visible = True 'at least for testing!

    Set WDDoc = WDApp.documents.Open(Filename:=myDocName)

    myPrintBackground = WDApp.Options.printbackground
    WDApp.Options.printbackground = False
    WDDoc.PrintOut
    WDApp.Options.printbackground = myPrintBackground
    WDDoc.Close savechanges:=False

    WDApp.Quit

    Set WDDoc = Nothing
    Set WDApp = Nothing

    End Sub

    If you step through the code, you should see a slight delay while the wdapp.quit
    is finishing up.


    BruceInMiami wrote:
    >
    > I found the answer in a 7/19/05 reply by Henry. I guess my problem was not
    > the wrdApp.PrintOut code, but that I needed to give Word time to print it
    > before closing it:
    > wrdApp.PrintOut
    > Application.Wait Time + TimeValue("00:00:05")
    >
    > If anyone has any further comments or clarifications I would appreciate it.
    > Thanks,
    > Bruce
    >
    > "BruceInMiami" wrote:
    >
    > > Thanks to John Walkenbach's Excel 2003 Power Programming, I can populate a
    > > Word template with Excel data and save the doc file, but I can't figure out
    > > the code to print the document so that I don't have to reopen it.
    > >
    > > Can anyone help?
    > > Thanks,
    > > Bruce


    --

    Dave Peterson

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1