473,387 Members | 1,760 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

How to close MS Word from VB.Net Application?

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.wdDoNot SaveChanges)
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
Nov 21 '05 #1
3 20716
"Bronislav" <Br*******@discussions.microsoft.com> 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.wdDoNot SaveChanges)
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.ReleaseCom Object' 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/>

Nov 21 '05 #2
Thank you, but MS Word still stays open. All documents are closing properly.
Thanks again.

"Herfried K. Wagner [MVP]" wrote:
"Bronislav" <Br*******@discussions.microsoft.com> 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.wdDoNot SaveChanges)
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.ReleaseCom Object' 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/>

Nov 21 '05 #3
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" <Br*******@discussions.microsoft.com> wrote in message
news:A3**********************************@microsof t.com...
Thank you, but MS Word still stays open. All documents are closing properly. Thanks again.

"Herfried K. Wagner [MVP]" wrote:
"Bronislav" <Br*******@discussions.microsoft.com> 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.wdDoNot SaveChanges)
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.ReleaseCom Object' 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/>

Nov 21 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: The Roys | last post by:
Hi Im doing something wrong in quitting the Word.Application in my VB program. I have General Declarations Dim AppWord As Word.Application Form_Load() Set AppWord =...
4
by: Microsoft | last post by:
I'm trying to display a word document inside a web page, but everytime I do I get this error: Error Type: Microsoft VBScript runtime (0x800A0046) Permission denied: 'CreateObject' Does...
2
by: Helene Day | last post by:
I did some experimentation in VB6 and VB.Net. With both applications, setting my Word.Application to nothing will not release winword.exe from memory. Also, I may have multiple copy of them......
0
by: Alto_chn | last post by:
I want to display the content of a word document in a text box when the filename is highlighted on a listbox. i used the following code to do it: Dim app As Word.Application app = New...
1
by: Jason Huang | last post by:
Hi, In my C# Windows form project, I would like to verify if a Word application (Word.ApplicationClass myWordApp) is not closed. What would the If statement be? Thanks for help. Jason
0
by: jorgedec | last post by:
I'm trying to use Office's FileSearch object to search for files. I'm using Visual Studio 2002 c# and Word 2000. The problem I am having is realeasing the Word.Application object. When I try to...
1
by: Flemming | last post by:
Hi I have created a word add-in and after having selected some documents into a listview the documents is opened and manipulated... with this code... wdApp = CType(GetObject("",...
0
by: Alan T | last post by:
I tried to close the word document object and word application: private Interop.Word.Application WordApp; private Interop.Word.Document WordDoc; // close word and quit word application ...
2
by: Alan T | last post by:
private Interop.Word.Application _wordApp; What is the differences betwenn _wordApp.Quit(...) and _wordApp.Application.Quit(...) ?
1
by: =?Utf-8?B?c3VydHVyeg==?= | last post by:
Hi, I'm using VB2005 + Office XP Enterprise. If you create a Word.Application object, you risk a memory leak if your application crashes because Word.Application is an unmanaged COM Interop...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.