PC Review


Reply
Thread Tools Rate Thread

How to close MS Word from VB.Net Application?

 
 
=?Utf-8?B?QnJvbmlzbGF2?=
Guest
Posts: n/a
 
      15th Nov 2004
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
 
Reply With Quote
 
 
 
 
Herfried K. Wagner [MVP]
Guest
Posts: n/a
 
      15th Nov 2004
"Bronislav" <(E-Mail Removed)> schrieb:
> 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, ...).

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>

 
Reply With Quote
 
=?Utf-8?B?QnJvbmlzbGF2?=
Guest
Posts: n/a
 
      15th Nov 2004
Thank you, but MS Word still stays open. All documents are closing properly.
Thanks again.

"Herfried K. Wagner [MVP]" wrote:

> "Bronislav" <(E-Mail Removed)> schrieb:
> > 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, ...).
>
> --
> M S Herfried K. Wagner
> M V P <URL:http://dotnet.mvps.org/>
> V B <URL:http://dotnet.mvps.org/dotnet/faqs/>
>
>

 
Reply With Quote
 
Imran Koradia
Guest
Posts: n/a
 
      15th Nov 2004
Have a look at this:
http://support.microsoft.com/default...b;EN-US;317109
you might want to follow the instructions in the article..

You can try calling ReleaseComObject in a loop till the reference count hits
zero:

Do While System.Runtime.InteropServices.ReleaseComObject() <> 0

Loop


hope that helps..
Imran.


"Bronislav" <(E-Mail Removed)> wrote in message
news:A3F8485A-88C1-487F-9BC9-(E-Mail Removed)...
> Thank you, but MS Word still stays open. All documents are closing

properly.
> Thanks again.
>
> "Herfried K. Wagner [MVP]" wrote:
>
> > "Bronislav" <(E-Mail Removed)> schrieb:
> > > 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, ...).
> >
> > --
> > M S Herfried K. Wagner
> > M V P <URL:http://dotnet.mvps.org/>
> > V B <URL:http://dotnet.mvps.org/dotnet/faqs/>
> >
> >



 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Before Close Event Hide all Worksheets then Close Application RyanH Microsoft Excel Programming 0 24th Jan 2008 03:15 PM
Word on close, 'normal.dot is used by another application or user' =?Utf-8?B?VG90byBTYW5kZXJzb24=?= Microsoft Word Document Management 1 2nd Jun 2006 09:15 PM
I Need Help ! Quit a word application and a Close word doc Tom Smith Microsoft Word New Users 2 11th Sep 2004 03:29 PM
How to close word application from C#.NET Nilesh Microsoft Word Document Management 0 25th Nov 2003 06:27 PM
Windows application does not close when i press the close button Umut Tezduyar Microsoft Dot NET Framework Forms 7 14th Aug 2003 08:57 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 06:32 PM.