By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
460,022 Members | 1,379 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 460,022 IT Pros & Developers. It's quick & easy.

Problem closing Word object from within C#

P: n/a
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

Jan 3 '06 #1
Share this Question
Share on Google+
1 Reply


P: n/a
> 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(...);

Jan 3 '06 #2

This discussion thread is closed

Replies have been disabled for this discussion.