我正在尝试查找打开的活动单词文档,并且如果打开了多个单词会话,哪个会话是活动单词会话,哪个处于前台。我开始:
对象关键词; Microsoft.Office.Interop.Word.Document wrddoc; winword = System.Runtime.InteropServices.Marshal.GetActiveObject(“ Word.Application”); wrddoc = winword.ActiveDocument;
这引发了一个错误,即“对象不包含ActiveDocument的定义,没有扩展方法...
我也尝试过此帖子(Get active word document object C#)
目标词; Word.Document _activeDocument;
try
{
word = System.Runtime.InteropServices.Marshal.GetActiveObject("Word.Application");
//If there is a running Word instance, it gets saved into the word variable
}
catch (Exception ex)
{
//If there is no running instance, it creates a new one
Type type = Type.GetTypeFromProgID("Word.Application");
word = System.Activator.CreateInstance(type);
}
Word.Application oWord = (Word.Application) word;
_activeDocument = oWord.ActiveDocument;
此代码引发错误“预期的捕获或最终出现在“ Word.Application oWord”上
关于我需要做什么的任何想法?最后,我试图找到活动的Word文档,以便将其保存到硬盘中。谢谢您的帮助。