Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Word Application Object - Quit method issues errors during compile 2

Status
Not open for further replies.

secureshell

Programmer
Sep 24, 2002
22
0
0
CA
Hi,

I am referencing the MS Word 11.0 Object Library v8.3 (COM) in my VB.NET project. Basically I am using word automation to prefill some word documents with data. All the members exposed by the Word object seem to work fine except for the "Quit" method that raises the following compile error if I call it anywhere in code:

Code:

Dim objWordApp as Word.Application

objWordApp = new Word.Application
....(code)
....(code)
....(code)
objWordApp.Quit

Error:

'Quit' is ambiguous across the inherited interfaces 'Word._Application' and 'Word.ApplicationEvents4_Event'.

If I don't use the Quit method, then the WINWORD.EXE process stays in memory after my application unloads and I don't want this.

Does anyone know the reason for this? Apparently, the Quit method for the same Word object functions as expected from VB6 code, so I am assuming this is due to the Managed/Unmanaged code interaction. Any suggestions would be great. TIA

secureshell

{W r i t e C o d e A n d K i c k A s s}
 
perhaps you should try

objwordapp = nothing

and then the garbage collection will remove it when neccessary, this not instant but should frre the memory when needed.

Christiaan Baes
Belgium

If you want to get an answer read this FAQ faq796-2540
What a wonderfull world - Louis armstrong
 
I should have mentioned in my previous post that I did try setting objWordApp = Nothing, hoping for the same thing but that doesn't work either. I have made sure that there are no other references in the code to this object and after completely shutting down the application and the IDE, WINWORD.EXE is still in memory. Its been over 15 minutes since I shutdown everything and I can still see it in the Task Manager. And this is the same process that was loaded due to a call made from within my application.

I know there are alternatives of killing processes in memory but I was hoping for a cleaner route than that.

{W r i t e C o d e A n d K i c k A s s}
 
Try this sequence:

objWordDoc = Nothing
objwordapp.Quit
objwordapp = Nothing
 
Here is the solution to the problem. The objWordApp had to be cast explicitly before calling the Quit method e.g:

CType(objWordApp, Word._Application).Quit()

This is due to the COM reference to the MS Word 11.0 Object Library. You can find a detailed explanation here:


Thanks to everyone who responded.

secureshell

{W r i t e C o d e A n d K i c k A s s}
 
thats the way to do it

Christiaan Baes
Belgium

If you want to get an answer read this FAQ faq796-2540
What a wonderfull world - Louis armstrong
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top