Closing of Word Application

G

GeorgeMar

I have a procedure that cycles through a list of Word
documents and prints them one at a time to the printer.
It works but the WINWORD.EXE remains open when viewed in
the Task Manager.

Here is the part of the procedure that is not working.

If Len(Dir(strFilename)) > 0 Then
Dim docWord As Object
Dim appWord As Object

Set appWord = CreateObject("Word.Application")
Set docWord = appWord.Documents.Open(strFilename)

docWord.PrintOut
docWord.Close
Set appWord = Nothing
End If

I thought that Set appWord=Nothing would close WINWORD.EXE.
Anything else I should do?

Perhaps I should also run the loop of Word documents
inside the opening and closing of appWord rather than
opening and closing the Word Application for each document.

Many thanks
George
 
V

Van T. Dinh

No. Set appWord = Nothing simply destroy the reference to the Word
application.

You need

appWord.Quit wdDoNotSaveChanges

after you close the doc and before you set the reference to Nothing.

You should also set docWord to Nothing.
 
G

GeorgeMar

Thank you Van

With regards to opening ang closing the Word Application,
is it more efficient to open the Word Application once and
cycle through printing the files or Opening and closing
the Word application for each print?

regards
george
 
V

Van T. Dinh

Much faster to open Word once, cycle through and print your docs and then
close Word.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top