将 VBA 宏转换为 C# 时 Document.Close() 上的 C# 歧义错误
C# ambiguity error on Document.Close() when converting VBA macro to C#
我正在转换为 C# 的 Word VBA 宏具有以下行。
我非常具体地在 Document
对象上使用 Close()
方法。我在下面没有找到任何能准确回答我的问题的问题。有类似个问题,比如这个:Compile time warning when using '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);
但是在最后一行我得到以下歧义错误:
Ambiguity between method
'Microsoft.Office.Interop.Word._Document.Close(ref object, ref object,
ref object)' and non-method
'Microsoft.Office.Interop.Word.DocumentEvents2_Event.Close'. Using
method group.
显然我无法重命名 Word 的 Close
方法(我猜),所以我尝试转换我的 oWordDoc
但似乎没有任何效果。
有人可以阐明如何正确地做到这一点吗?谢谢。
将其投射到 Microsoft.Office.Interop.Word._Document
,其中不包含该事件。
((Microsoft.Office.Interop.Word._Document)oWordDoc).Close(Word.WdSaveOptions.wdDoNotSaveChanges, oMissing, oMissing);
我正在转换为 C# 的 Word VBA 宏具有以下行。
我非常具体地在 Document
对象上使用 Close()
方法。我在下面没有找到任何能准确回答我的问题的问题。有类似个问题,比如这个:Compile time warning when using '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);
但是在最后一行我得到以下歧义错误:
Ambiguity between method 'Microsoft.Office.Interop.Word._Document.Close(ref object, ref object, ref object)' and non-method 'Microsoft.Office.Interop.Word.DocumentEvents2_Event.Close'. Using method group.
显然我无法重命名 Word 的 Close
方法(我猜),所以我尝试转换我的 oWordDoc
但似乎没有任何效果。
有人可以阐明如何正确地做到这一点吗?谢谢。
将其投射到 Microsoft.Office.Interop.Word._Document
,其中不包含该事件。
((Microsoft.Office.Interop.Word._Document)oWordDoc).Close(Word.WdSaveOptions.wdDoNotSaveChanges, oMissing, oMissing);