Solved

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

Posted on 2006-11-14
4
929 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

Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction When many people think of the WebBrowser (http://msdn.microsoft.com/en-us/library/2te2y1x6%28v=VS.85%29.aspx) control, they immediately think of a control which allows the viewing and navigation of web pages. While this is true, it's a…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

770 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