PDA

View Full Version : Outlook Macro leaves Winword.exe process running



rberke
07-20-2012, 02:24 PM
My users can call an Outlook macro that will pre-format a reply to an email. When the macro is done, there is a winword process that is "left behind". It remains running even if outlook is closed.

Here is a stripped down version of the code code. Does anybody have any suggestions?

Sub testit()

Dim word As Object, newitem As Object, obj As Object

MsgBox "to simplify testing, I always kill winword first"
Set obj = CreateObject("WScript.Shell")
obj.Run "taskkill /IM winword.EXE /F", 1, True
Set obj = Nothing

Set word = CreateObject("word.application")
Set newitem = Application.ActiveExplorer.selection.item(1).Reply
newitem.Display
newitem.Close olDiscard
For Each obj In word.Documents
obj.Close False
Next


word.NormalTemplate.saved = True
word.Quit
Set newitem = Nothing
Set obj = Nothing
Set word = Nothing
MsgBox "WinWord is still running"

End Sub

I also tried variations using
Set word = newitem.GetInspector.WordEditor.Application, but those have the same problems.

rberke

p.s. I don't want to try using Getobject because I have discovered that reusing a user created instance of word leads to troubles.

JP2112
07-22-2012, 05:21 PM
I'm confused, you create an instance of Word, then immediately close any open documents:

For Each obj In word.Documents
obj.Close False
Next

Then you immediately save and quit Word.

word.NormalTemplate.saved = True
word.Quit

Is there some code you haven't posted?