0x80010105(RPC_E_SERVERFAULT)使用C#执行MailMerge时

时间:2016-03-12 17:38:33

标签: c# mailmerge

我在使用C#保存邮件合并文档时收到以下错误消息,但在使用Office 2007时。保存方法适用于比2007年更新的办公室版本。我在此行上收到该错误消息命令:

_wordApp.ActiveDocument.SaveAs2(string.Format(path + "\\temp\\" + @"MailMerge.docx"));

非常感谢任何协助。

  

错误消息:服务器引发异常(来自HRESULT的异常:0X90010105(RPC_E_SERVERFAULT))

代码:

 try
 {
     statusLabelStrip.Text = "Currently cleaning up data.  Please wait.";

     _wordApp.Visible = false;
     _wordApp.DisplayAlerts = Microsoft.Office.Interop.Word.WdAlertLevel.wdAlertsNone;

     oDoc.MailMerge.MainDocumentType = Microsoft.Office.Interop.Word.WdMailMergeMainDocType.wdMailingLabels;
     oDoc.MailMerge.OpenDataSource(csvFileName, false, false, true, false);


     oDoc.MailMerge.Destination = Microsoft.Office.Interop.Word.WdMailMergeDestination.wdSendToNewDocument;
     oDoc.MailMerge.Execute(false);
     oDoc.MailMerge.DataSource.Close();
     oDoc.MailMerge.MainDocumentType = Microsoft.Office.Interop.Word.WdMailMergeMainDocType.wdNotAMergeDocument;
     oDoc.Close(Microsoft.Office.Interop.Word.WdSaveOptions.wdDoNotSaveChanges);// this will save the template if changed
    // oDoc.Save(); // this will save the template
    // oDoc = null;
 }

 catch (Exception ex)
 {
     MessageBox.Show("Office Version: " + sVersion + "\r\n" + "Process Error 3: " + 
ex.Message + "\r\n" + ex.StackTrace, "Mail Merge Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
 }
 finally
 {
     try 
     {
         if (_wordApp != null)
         {
             //_wordApp.Documents.Save(true); //this will prompt the SaveAs box
             //_wordApp.ActiveDocument.MailMerge.Execute();

             _wordApp.ActiveDocument.SaveAs2(string.Format(path + "\\temp\\" + @"MailMerge.docx"));
             _wordApp.Quit(Microsoft.Office.Interop.Word.WdSaveOptions.wdSaveChanges);
             System.Runtime.InteropServices.Marshal.FinalReleaseComObject(_wordApp);

0 个答案:

没有答案