locked
Excel AutoRecover not working with Excel Interop RRS feed

  • Question

  • I have a simple C# application where I am creating an instance of an Excel application and opening a document using it. Here is the code I am using :

    m_excelApplication = new Microsoft.Office.Interop.Excel.Application(); // m_excelApplication is the Excel application object m_excelApplication.Workbooks.Open(templatePath); // templatePath is of the form "C:\\Users\\Developer\\abc.xls";

    m_excelApplication.Visible = true;

    The document opens successfully. However, when I make some changes in the document (the changes are not saved) and wait for the Auto Recovery to fire, no AutoRecovery file is created at the specified location (the location specified under Options->Save->AutoRecover File Location).

    I have also verified that the AutoRecovery settings are all correct (the AutoRecovery information is saved every 1 minute and "Disable AutoRecover for this workbook only" is not checked)

    I also verified that AutoRecovery is working for documents which are not opened through the above code (i.e I closed all excel instances and opened a simple Excel document from the desktop and made some changes in it. After 1 minute, an  autorecovered file is being created for this opened document)

    Has anyone else had this problem in regards to autoRecovery not working? As mentioned, this is specifically happening for Excel application instances created using Excel Interop? I am using Excel 2010.

    Thanks,

    Akshay



    • Edited by akbh82 Monday, September 15, 2014 12:13 PM
    Monday, September 1, 2014 9:33 AM

Answers

  • Hi Akshay,

    Autosave does not operate until Excel is idle for a certain period. When Excel is automated, Excel is not idle. Due to this, Autosave doesn't occur. To save document during automation, it is suggested to save using the Save method.

    Thanks,

    Anush.

    • Proposed as answer by AnushRudaa Tuesday, September 16, 2014 10:19 PM
    • Marked as answer by akbh82 Thursday, September 18, 2014 6:58 AM
    Tuesday, September 16, 2014 10:19 PM

All replies

  • Hello Akshay,

    > I have a simple C# application where I am creating an instance of an Excel application and opening a document using it.

    How and where do you use VSTO then???

    Did you try to open the file from another drive? Do you expirience the same issue?

    Did you try to use another newly created file? Just place there a newly created file and try to run the code against it. Does it work?

    Monday, September 1, 2014 11:18 AM
  • Hi Eugene,

    Thanks for your prompt reply. Regarding VSTO, I have this application for opening Excel documents and an Excel Addin targetting Excel 2010. Hence, I mentioned VSTO (because of this addin) but this problem is specific to the code mentioned above.

    So back to your suggestions, I have tried opening from different drives, tried on different machines (32 bit and 64 bit both having 32 bit Office 2010) and tried with multiple Excel files. However, the outcome is still the same. The auto-recovery just fails to run.

    Akshay

    Tuesday, September 2, 2014 6:04 AM
  • Hi Akshay,

    I'd suggest releasing all the underlying COM objects instantly. Use System.Runtime.InteropServices.Marshal.ReleaseComObject to release an Excel object when you have finished using it. Then set a variable to Nothing in Visual Basic (null in C#) to release the reference to the object.

    Don't forget to disable all add-ins enabled in Excel before testing the code. It may cause the issue also.

    Tuesday, September 2, 2014 11:49 AM
  • Hi Eugene,

    I have tried using Marshal.ReleaseComObject and Marshal.FinalReleaseComObject both and setting the reference to null. I also ensured that there were no Active Application Add-ins. This still does not fix the issue.

    Akshay


    Wednesday, September 3, 2014 11:10 AM
  • Hi Akshay,

    Thanks for posting in MSDN forum.

    I reproduced this issue successully. Since this issue is complex, I'm trying to involve some senior engineers into this issue and it will take some time. Your patience will be greatly appreciated.

    Sorry for any inconvenience and have a nice day!

    Best regards

    Fei 


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Wednesday, September 10, 2014 9:48 AM
  • Hi Akshay

    You mention VSTO in the subject line, but I don't see anything about the Tools in your problem description? VSTO is a special set of tools for creating Add-ins or workbooks linked to code. If you're not using VSTO then we need to edit your subject line and then move your question to the Excel for Developers forum...


    Cindy Meister, VSTO/Word MVP, my blog

    Friday, September 12, 2014 7:40 PM
  • Hi Cindy,

    My solution is a combination of C#DLL and an Excel Addin. The C# DLL is responsible for opening the Excel documents. Once the documents are opened, the addin comes into the picture.

    The specific problem mentioned above is happening when documents are opened through the C# DLL. The DLL is using Excel Interop to open the Excel documents. For these documents, autorecovery is not working. So technically VSTO doesn't come in to the picture here as the problem is with opening the documents in the C# DLL.

    I have changed the VSTO in the Subject line to Excel Interop.

    Thank You

    Akshay

    Monday, September 15, 2014 12:14 PM
  • Hi Akshay,

    Autosave does not operate until Excel is idle for a certain period. When Excel is automated, Excel is not idle. Due to this, Autosave doesn't occur. To save document during automation, it is suggested to save using the Save method.

    Thanks,

    Anush.

    • Proposed as answer by AnushRudaa Tuesday, September 16, 2014 10:19 PM
    • Marked as answer by akbh82 Thursday, September 18, 2014 6:58 AM
    Tuesday, September 16, 2014 10:19 PM
  • Hi Ankush,

    Thanks for your reply. Now it makes sense why autorecovery with automated Excel doesn't work at all.

    Thanks,

    Akshay

    Thursday, September 18, 2014 6:58 AM