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.
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.