我要转换为C#的Word VBA宏具有以下行。我非常具体地Close()
在Document
对象上使用该方法。我没有找到任何可以完全回答我以下问题的问题。也有类似的问题,例如这一问题:使用“ 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”之间的歧义。使用方法组。
显然,我无法重命名Close
Word的方法(我想),因此我尝试强制转换,oWordDoc
但似乎无济于事。
有人可以阐明如何正确执行此操作吗?谢谢你。
将其强制转换为Microsoft.Office.Interop.Word._Document
,其中不包含该事件。
((Microsoft.Office.Interop.Word._Document)oWordDoc).Close(Word.WdSaveOptions.wdDoNotSaveChanges, oMissing, oMissing);
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句