I'm receiving the below error message when saving the mail merge document using C#, but while using office 2007. The save method works on versions of office newer than 2007. I receive that error message on the line with this command:
_wordApp.ActiveDocument.SaveAs2(string.Format(path + "\\temp\\" + @"MailMerge.docx"));
Any assistance would be greatly appreciated.
Error Message: The server threw an exception (Exception from HRESULT: 0X90010105 (RPC_E_SERVERFAULT))
Code:
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);
User contributions licensed under CC BY-SA 3.0