Closing of Word Application

  • Thread starter Thread starter GeorgeMar
  • Start date Start date
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
 
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.
 
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
 
Much faster to open Word once, cycle through and print your docs and then
close Word.
 
Back
Top