Results 1 to 4 of 4

Thread: printing a word document

  1. #1

    Thread Starter
    Frenzied Member
    Join Date
    Aug 2000
    Location
    Birmingham, AL
    Posts
    1,276

    Question printing a word document

    Add a reference to 'Microsoft Word 9.0 Object Library'

    I'm trying to print a document with this code:
    Code:
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    
        Dim wrdApp As New Word.Application
    
        wrdApp.Documents.Open("C:\temp\temp.doc")
    
        wrdApp.Dialogs.Item(Word.WdWordDialog.wdDialogFilePrint).Show()
    
        wrdApp.Visible = False
    
        wrdApp.ActiveDocument.Close()
    
        wrdApp.Quit()
    
    End Sub
    The problem is, when the print dialog shows up and I click OK to print, I get the Message 'Word is currently printing. Quitting Word will cancel all pending print jobs. Do you want to quit Word?'

    If I click Yes the document is not printed but Word disappears. Clicking No, the document prints but the Word application is still open and has to be closed manually.

    Is there a way to tell when the Word app is fininished sending the document to the printer so I can call wrdApp.Quit()?

  2. #2
    Frenzied Member Mike Hildner's Avatar
    Join Date
    Jul 2002
    Location
    Des Moines, NM
    Posts
    1,690
    Not sure if this will help you or not. I have not printed a Word doc from .NET. But, in a Word macro, I've had to use
    Code:
    ActiveDocument.PrintOut (False)
    which suspends the macro until the print job is done, avoiding a similar dialog box.

    FWIW, I tried your code verbatim, printed to Adobe PDF, and did not have any problems.

    Best of luck,
    Mike

  3. #3
    Frenzied Member
    Join Date
    May 2004
    Location
    Carlisle, PA
    Posts
    1,045
    wey97:

    Looking at the Word VB Help Heap, in PrintOut:

    wrdApp.ActiveDocument.PrintOut(Background:=False)

    Means that Printing is in the foreground, and the macro shouldn't continue util the print job is done. ???

    I've started a thread about how to pass a print file name to Adobe PDF writer as the default Word Printer. Any ideas?
    Blessings in abundance,
    All the Best,
    & ENJOY!

    Art . . . . Carlisle, PA . . USA

  4. #4

    Thread Starter
    Frenzied Member
    Join Date
    Aug 2000
    Location
    Birmingham, AL
    Posts
    1,276
    I was using the .PrintOut method but I had to make a custom dialog to get the page range. It was screwing up the page range so I went to the System Print Dialog. Plus you get all the other printing options with the system dialog.

    The only way around it was to wait a certain amount of time (like 10 seconds) to make sure the document finished printing and kill the Word process. The problem with that is if you click Print and immediately exit the app you have an extra Word process running in the background.

Posting Permissions

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



Click Here to Expand Forum to Full Width