How to close MS Word from VB.Net Application?

G

Guest

In the Main form of my application I declare
Friend Shared WithEvents WordApp As New Word.Application()
And it works fine
When I'm living an application I try to close MS Word
WordApp.Documents.Close(Word.WdSaveOptions.wdDoNotSaveChanges)
WordApp.Quit(Word.WdSaveOptions.wdDoNotSaveChanges)
WordApp = Nothing
First Line works fine. Second line give error in the VB.Net 2002 and do not
give error in the VB.NET 2003 but MS WORD state open. If I open the
application again a second instance of the MS Word will be opened and so on.
Can somebody tell me what wrong with this approach.
Thanks, Bronislav
 
H

Herfried K. Wagner [MVP]

Bronislav said:
Friend Shared WithEvents WordApp As New Word.Application()
And it works fine
When I'm living an application I try to close MS Word
WordApp.Documents.Close(Word.WdSaveOptions.wdDoNotSaveChanges)
WordApp.Quit(Word.WdSaveOptions.wdDoNotSaveChanges)
WordApp = Nothing
First Line works fine. Second line give error in the VB.Net 2002 and do
not
give error in the VB.NET 2003 but MS WORD state open. If I open the
application again a second instance of the MS Word will be opened and so
on.

Call 'System.Runtime.InteropServices.Marshal.ReleaseComObject' on each COM
object ('WordApp', document objects, ...).
 
G

Guest

Thank you, but MS Word still stays open. All documents are closing properly.
Thanks again.
 

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