locked
Attempting to access workbook saved property in BeforeClose raises HRESULT 0x8004010A8 error RRS feed

  • Question

  • I have a Excel add-in and subscribe to the Excel.BeforeClose event handler, as below:

    Excel.AppEvents_WorkbookBeforeCloseEventHandler(m_goWorkbook_BeforeClose);

    public void m_goWorkbook_BeforeClose(Excel.Workbook toWorkbook, ref bool tbCancel)
    {
    // stuff
    if (toWorkbook.Saved)
    {
    // do something 
    }
    }

    the line (toWorkbook.Saved) causes an HRESULT 0x800401A8 error every time.  I can access other properties such as toWorkbook.Name, just not saved.
    Friday, April 27, 2018 10:08 PM

All replies

  • Hello kptools,

    What application are you developing? Is it an VSTO application?

    What's the version of your office? Will this error occur on a Saved workbook or an unsaved workbook? Or both?

    If you try to try...catch the error, could you get a detail error message for the issue?

    Best Regards,

    Terry


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Saturday, April 28, 2018 2:39 AM
  • It is VSTO for Excel.  I have separately compiled versions for Excel 2007, 2010, 2013, and 2016 and the error is in all and also occurs irrespective of the saved state of the workbook (or if it is new or pre-existing). I do try/catch the error which is 'Exception from HRESULT: 0x800401A' - the call stack trace is from Microsoft.Office.Interop.Excel_Workbook.get_Saved().

    Saturday, April 28, 2018 6:48 AM
  • Hello kptools,

    >>I have separately compiled versions for Excel 2007, 2010, 2013, and 2016 

    separately compiled? Did you install multiple version of Office in same computer?

    >> I do try/catch the error which is 'Exception from HRESULT: 0x800401A' - the call stack trace is from 

    Would you mind share a simply project and tell us the reproduce steps so we could try to use it to reproduce your issue? For sharing file, you could try to share it via Cloud Storage, such as One Drive, and the put link address here.

    Thanks for understanding,

    Best Regards,

    Terry


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Saturday, April 28, 2018 7:31 AM
  • the code is fairly complex and is for a document management system.  the code allows retrieval of a file from a server to a local folder and opens the local folder copy.  when the user wants to close and save the file, the local file is checked to see if it is saved.  if not, the user is allowed to save, not save, or cancel.  if save/not_save, the local file is closed, copied to the server, and then deleted from the local folder.
    Saturday, April 28, 2018 6:23 PM
  • Hello kptools,

    >>I have separately compiled versions for Excel 2007, 2010, 2013, and 2016 

    Did you install multiple version of Office in same computer?

    >>the code allows retrieval of a file from a server to a local folder and opens the local folder copy...

    I would suggest you create a new project and try to simply the code to reproduce the statement as you state.  This test is to check if any operation in your original project caused this issue. If it still occur, please share the simplified code so we could try to reproduce your issue.

    Best Regards,

    Terry


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Thursday, May 3, 2018 5:26 AM
  • At this juncture what I think was happening is that in the beforeclose code i was closing the workbook explicitly (workbook.close()) to allow me to do other things.  this explicit call to close() seems to invoke beforeclose again, but, of course, the workbook's state is likely "closed" by then.  the second invocation occurred even though the code itself unsubscribed to the beforeclose.  I added code to prevent this second call and that seems to have fixed the problem  however, i have not fully verified that.
    Thursday, May 3, 2018 10:32 AM
  • Hello kptools,

    I'm glad to hear that your issue is fixed. I would suggest you mark your solution to close the thread. If you have any other issue, please feel free to post new thread to let us know.

    Best Regards,

    Terry


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Friday, May 4, 2018 5:56 AM
  • just for the sake of completeness, I have multiple development machines, each with a version of Office.  no one machine has multiple versions.  I then run a version of the software on each such machine where the version of the software is specific to that machine's version of Office.
    Friday, May 4, 2018 1:19 PM