Hello Everyone,
I am using Interop Word and Excel in my .NET code to override few of the functionalities of Word/ Excel. This is when I am getting few problems and you are the only hope left for the correct answer :confused:
I need to override the Save function of office and needs to save the Doc I want and then needs to close the current document.
For this, I am using the following codes:
Word:
MVSTODocument.SaveAs(ref filePath, ref fileSaveFormat, ref fileLockComments, ref missing, ref isAddToRecentFiles , ref missing, ref isFileReadOnly, ref fileEmbedTrueTypeFonts, ref fileSaveNativePictureFormat, ref fileSaveFormsData , ref isSaveAsAOCELetter, ref fileMSOEncoding, ref fileInsertLineBreaks, ref fileAllowSubstitutions, ref fileLineEncoding, ref fileAddBiDiMarks);
MVSTODocument.Close(ref fileSaveOptions, ref fileSaveFormat, ref LbIsToSave)
Excel:
MVSTOWorkbook.SaveCopyAs(LstrTempFileFullPath);
InteropExcel_.Workbook workBook = MVSTOWorkbook.Application.Workbooks.Open(LstrTempFileFullPath, Type.Missing, Type.Missing, Type.Missing, Type.Missing,Type.Missing, Type.Missing, Type.Missing, Type.Missing,Type.Missing, Type.Missing, Type.Missing, Type.Missing,Type.Missing, Type.Missing);
workBook.Close(false, LstrTempFileFullPath, null);
Marshal.ReleaseComObject(workBook);
MVSTOWorkbook.Close(false, objApp.ActiveWorkbook.Name, Type.Missing);
The Reason I din't use 'SaveAs' in excel because it stopped working when I moved from Office 2007 to Office 2010.
Now the Problem I am facing is - When I run this code. It works perfectly fine with Excel but for Word it throws a COM exception which crashes the Word App.
31982216 mov esi,dword ptr [edi+2ACh]
Unhandled exception at 0x31982216 in WINWORD.EXE: 0xC0000005: Access violation reading location 0x000002ac.
The weird thing is my the debugger leaves perfectly fine till my .NET code.
The only thing I noticed is that may be because COM calls the Workbook.Save()/ Document.Save() method whenever my there is a cross app call. Excel has a null check implemented and Word does not have. Is that true? Can I Stop this weird behavior?
Any pointers will be appreciated.
Thanks.
Any suggestions?