Click here to Skip to main content
15,892,965 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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:
VB
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:
VB
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?
Posted
Comments
aidin Tajadod 9-Nov-10 12:01pm    
What is your system language setting? I had a weird problem before and it was for may windows language settings.
Member 3335462 9-Nov-10 13:20pm    
@Aidin :
The System Language is set to English (United States). But My code needs to be Language independent as this has to work with different cultures.
aidin Tajadod 9-Nov-10 19:58pm    
So it should not be your problem.
I remember I had to create a CultureInfo with US and assign it to the current thread culture when I wanted to work with Excel! ( Sorry I do not remember the details)

1 solution

I have solved this issue by calling my Close document call asynchronously using a timer tick. And it works fine !!!

Though, I really don't know that why? :)

But now I am facing another issue i.e. even though I am killing my Save document event whenever user clicks 'Save As', it still shows me that stupid 'Save As' dialog window.

Why Word behaves so Weird always ?! The same thing works perfect in Excel...
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900