471,330 Members | 1,783 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

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

Problem closing Word object from within C#

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
1 8924
> 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.

Similar topics

6 posts views Thread by Iain Bishop | last post: by
24 posts views Thread by Robi | last post: by

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.