繁体   English   中英

将VBA宏转换为C#时,Document.Close()出现C#模糊性错误

[英]C# ambiguity error on Document.Close() when converting VBA macro to C# [duplicate]

这个问题已经在这里有了答案:

我要转换为C#的Word VBA宏具有以下行。 我非常专门在Document对象上使用Close()方法。 我没有找到任何可以完全回答我以下问题的问题。 也有类似的问题,例如这一问题: 使用“ Microsoft.Office.Interop.Word._Document.Close”时的编译时间警告

但是看着它,我无法弄清楚我必须使用的确切类型。

ActiveDocument.Close wdDoNotSaveChanges

我这样将其转换为C#:

using Microsoft.Office;
using Microsoft.Office.Interop;
using Word = Microsoft.Office.Interop.Word;

Object oMissing = System.Reflection.Missing.Value;
Word.Document oWordDoc = new Word.Document();

oWordDoc.Close(Word.WdSaveOptions.wdDoNotSaveChanges, oMissing, oMissing);

但是,在最后一行,我得到以下歧义错误:

方法“ Microsoft.Office.Interop.Word._Document.Close(引用对象,引用对象,引用对象)”和非方法“ Microsoft.Office.Interop.Word.DocumentEvents2_Event.Close”之间的歧义。 使用方法组。

显然,我无法重命名Word的Close方法(我想),因此我尝试转换oWordDoc但似乎无济于事。

有人可以阐明如何正确执行此操作吗? 谢谢。

将其强制转换为不包含该事件的Microsoft.Office.Interop.Word._Document

((Microsoft.Office.Interop.Word._Document)oWordDoc).Close(Word.WdSaveOptions.wdDo‌​NotSaveChanges, oMissing, oMissing);

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM