none
Excel COMException : 0x800A03EC Document not saved. RRS feed

  • Question

  • Hello,

    I am using Interop.Excel in my WinForms application. The application is used to copy some sheets from one workbook to newly created one.

    The newly created workbook is saved when I don't copy shapes. But, when I copy shapes into newly created sheet, the workbook is not saved and COMException is raised with message "Document not saved".

    Scenario :

    I am working with three workbooks simultaneously. 

    MainWorkbook - this workbook contains data to be written into new workbook.

    ResourceWorkbook - this contains sheets that are copied into new workbook.

    OutputWorkbook - this is the result workbook.

    Step 1: Open MainWorkbook. Get data to write in OutputWorkbook.

    Step 2: Write data into OutputWorkbook.

    Step 3: Open ResourceWorkbook from resource file for copying the sheets.

    Step 4: Copy sheets from ResourceWorkbook into OutputWorkbook.

    Step 5: Save OutputWorkbook.

    In step 5, if there are no sheets with images copied in step 4, then the OutputWorkbook is saved. But, if there are sheets containing images, the OutputWorkbook is not saved.

    I am using VS2010 and MS Office 2010.

    Wednesday, April 22, 2015 9:00 AM

Answers

  • Hi,

    I figured out the problem. It had more to do with BackGroundWorker thread in Visual C#. 

    I saved the workbook. Then after the execution of BackGroundWorker completed, again opened the workbook and copied the sheet and it worked. 

    I guess it was probably because I was using the same Excel Application in BackGroundWorker and main thread.

    Thanks for your suggestion.

    Thursday, April 23, 2015 8:45 AM

All replies

  • Hello,

    > But, when I copy shapes into newly created sheet, the workbook is not saved and COMException is raised with message "Document not saved".

    What code do you use for copying shapes?

    > I am using Interop.Excel in my WinForms application.

    The forum is for VSTO specific questions. That's why I'd suggest asking Excel specific questions on the Excel for Developers  forum instead.

    Wednesday, April 22, 2015 4:31 PM
  • I am using C#.
    Thursday, April 23, 2015 2:55 AM
  • Hi,

    According to the description, the issue seems that relative to the specific worksheet which containd shapes.

    I am trying to reproduce this issue in Excel 2010 using VBA, howerever it failed. Here is the test sample which set write the value to the Book2 and copy the worksheet contained shapes from Book1 to Book2:

    Sub CopySheet()
    
    Application.Workbooks("Book2.xlsx").Worksheets("Sheet1").Range("A1") = "Hello Word!"
    Worksheets("Sheet1").Copy Application.Workbooks("Book2.xlsx").Worksheets("Sheet1")
    
    Application.Workbooks("Book2.xlsx").Save
    End Sub
    

    Could you reproduce the issue with code above? If not, a sample worksheet and code snippet to help us reproduce this issue is much appericate.

    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.

    Thursday, April 23, 2015 8:25 AM
    Moderator
  • Hi,

    I figured out the problem. It had more to do with BackGroundWorker thread in Visual C#. 

    I saved the workbook. Then after the execution of BackGroundWorker completed, again opened the workbook and copied the sheet and it worked. 

    I guess it was probably because I was using the same Excel Application in BackGroundWorker and main thread.

    Thanks for your suggestion.

    Thursday, April 23, 2015 8:45 AM
  • Office applications uses the single threaded apartment model. You need to access the Office object model (Word in your case) on the main thread. If you need to do some processing on the background thread you may extract all the required information or data and process it on the secondary thread without involving Word objects.

    Thursday, April 23, 2015 10:31 AM
  • Hi,

    As Eugene's suggestion, Office applications use single-threaded apartments. It is not suitble that use Office object model in many threads.

    Also the Office automation is based on COM, it would failed if Office application is busy, we need to use exception handle for this secnario.

    Hope it is helpful.

    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.

    Friday, April 24, 2015 7:20 AM
    Moderator