if (!axWebBrowserRptContent.IsDisposed)//定义的一个允许在窗体内浏览网页的WebBrowser控件
      {//WebBrowser控件打开了oApplication的word应用,里面打开一个oDocument文档                               
         SaveWord();//定义的保存word的函数 
         Object refmissing = System.Reflection.Missing.Value;  
        axWebBrowserRptContent.Navigate("about:blank", ref refmissing, ref refmissing, ref refmissing, ref refmissing);
        object doNotSaveChanges = Word.WdSaveOptions.wdDoNotSaveChanges; 
        if (oDocument != null) oDocument.Close(ref doNotSaveChanges,ref refmissing,ref refmissing);
        if (oApplication != null) oApplication=null;
      }
运行到黑体部分时报错“此方法或属性无效 因为 此文档在另一应用程序中 ”,烦请大哥赐教!

解决方案 »

  1.   

    黑体是哪一句?
    是否是SaveWord();
    这一句?
      

  2.   

    我测试下 
    没有你出现的问题            //Word.ApplicationClass WordApp = new Word.ApplicationClass();            //// give any file name of your choice. 
                //object fileName = "D:\\aa.doc";
                //object readOnly = false;
                //object isVisible = false;            ////  the way to handle parameters you don't care about in .NET 
                //object missing = System.Reflection.Missing.Value;
                //WordApp.Visible = false;
                ////   Make word visible, so you can see what's happening 
                ////WordApp.Visible = true; 
                ////   Open the document that was chosen by the dialog 
                //Word.Document aDoc = WordApp.Documents.Open(ref fileName,
                //                        ref missing, ref readOnly, ref missing,
                //                        ref missing, ref missing, ref missing,
                //                        ref missing, ref missing, ref missing,
                //                         ref missing, ref isVisible, ref missing, ref missing, ref missing, ref missing);            //Word.WdStatistic stat = Word.WdStatistic.wdStatisticPages;
                //int num = aDoc.ComputeStatistics(stat, ref missing);
                //System.Console.WriteLine("The number of pages in doc is {0}",
                //                          num);            //foreach (Word.Range r in aDoc.Words)
                //{
                //    Debug.WriteLine("value:" + r.Text);
                //}
                //System.Console.ReadLine();
                //object o = false;
                //aDoc.Close(ref o, ref missing, ref missing);
                //WordApp.Quit(ref o, ref missing, ref missing);