Problem closing Word object from within C#

R

Ronald S. Cook

Sorry for the previous duplicate posts.

I'm referencing and using the Microsoft Word 11.0 object model from within
my VS 2005 C# Windows app.

The following lines...

objWordDoc.Close(ref missing, ref missing, ref missing);
objWordApp.Quit(ref missing, ref missing, ref missing);

Give me the following errors:

Ambiguity between method 'Word._Document.Close(ref object, ref object, ref
object)' and non-method 'Word.DocumentEvents2_Event.Close'
Ambiguity between method 'Word._Application.Quit(ref object, ref object, ref
object)' and non-method 'Word.ApplicationEvents4_Event.Quit'

So I can't seem to close Word. Any idea how to get around it?

Thanks for any help!
Ron
 
P

Paul Henderson

The following lines...
objWordDoc.Close(ref missing, ref missing, ref missing);
objWordApp.Quit(ref missing, ref missing, ref missing);

Give me the following errors:

Ambiguity between method 'Word._Document.Close(ref object, ref object, ref
object)' and non-method 'Word.DocumentEvents2_Event.Close'
Ambiguity between method 'Word._Application.Quit(ref object, ref object, ref
object)' and non-method 'Word.ApplicationEvents4_Event.Quit'

Those should just be warnings from the compiler, rather than errors; it
should still be able to build the code in theory, as it can resolve the
ambiguity by making a method group and using the matching overload.

The problem is because the objects expose a Close/Quit method and a
Close/Quit event, declared in different interfaces so they can have the
same name. So, you should just need to cast down to the correct
interface, like
((_Document)objWordDoc).Close(...);
((_Application)objWordApp).Quit(...);
 

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