Solved

WINWORD.EXE not closing after mWordObject.ActiveDocument.PrintOut()

Posted on 2006-11-14
4
924 Views
Last Modified: 2008-01-09
I have a requirement where i need to print set of documents and this is working fine. But all the WINWORD.EXE's for each document are staying in Task Manager and i have to manually end all the processes.

Please let me know how to overcome this. If i do this

                mWordObject.Application.Quit()
                mWordObject = Nothing

It closes the WINWORD.EXE but it closes even before it prints. I want to know if there is a method which can find when the printing is done and then closes the WINDWORD.EXE files.

Any help/suggestions would be really helpful.

Thanks
Sureshj
0
Comment
Question by:smaram1
  • 2
4 Comments
 

Author Comment

by:smaram1
ID: 17942524
Actually this doesnt work too...

                mWordObject.Application.Quit()
                mWordObject = Nothing
0
 
LVL 16

Expert Comment

by:Hillwaaa
ID: 17944792
Hi smaram1,

Try the following:

mWordObject.ActiveDocument.PrintOut()
Do While objWord.BackgroundPrintingStatus > 0
Loop

mWordObject.Application.Quit()
mWordObject = Nothing

Let me know if that doesn't work.

Cheers!
0
 
LVL 16

Accepted Solution

by:
Hillwaaa earned 250 total points
ID: 18136192
To verify my solution, here's a sample hello world scenario - where a new document is created, hello world written to the new doc, it is printed, and after the printing is complete, the doc is closed.

        Dim oWord As Microsoft.Office.Interop.Word.Application
        Dim oDoc As Microsoft.Office.Interop.Word.Document
        Dim oPara1 As Microsoft.Office.Interop.Word.Paragraph

        oWord = CreateObject("Word.Application")
        oWord.Visible = True
        oDoc = oWord.Documents.Add

        'Insert a paragraph at the beginning of the document.
        oPara1 = oDoc.Content.Paragraphs.Add
        oPara1.Range.Text = "Hello World!"
        oPara1.Range.Font.Bold = True

        oWord.ActiveDocument.PrintOut()

        'Wait for printing to complete.
        Do While oWord.BackgroundPrintingStatus > 0
        Loop

        oDoc.Close(False) 'Close without saving

        oWord.Application.Quit()
        oWord = Nothing
0

Featured Post

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

Article by: jpaulino
XML Literals are a great way to handle XML files and the community doesn’t use it as much as it should.  An XML Literal is like a String (http://msdn.microsoft.com/en-us/library/system.string.aspx) Literal, only instead of starting and ending with w…
1.0 - Introduction Converting Visual Basic 6.0 (VB6) to Visual Basic 2008+ (VB.NET). If ever there was a subject full of murkiness and bad decisions, it is this one!   The first problem seems to be that people considering this task of converting…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

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

16 Experts available now in Live!

Get 1:1 Help Now