none
How to detect in C# if Excel Worksheet closes. RRS feed

  • Question

  • I have an Excel plugin in an old app, in .Net2003, written in C#.    I have found events to detect when a workshheet is added to a workbook (NewSheet), but have found no way to detect when a Worksheet is closed/deleted.   
    Friday, September 4, 2009 3:17 PM

Answers

  • Hi Redd Green,

    Yes, we don't have a event in Excel Objece Model to track the Worksheet deleting, but we could have a work around, we could take use of Workbook.SheetActivate and Workbook.SheetDeactivate event, when a Worksheet is being deleted, it will fire a Workbook.SheetDeactivate event, and then a Workbook.SheetActivate event, in Workbook.SheetActivate event, if we test the Workbook.Worksheets.Count property we'll find that the count number is decreased by 1 when we test the same property in Workbook.SheetDeactivate.

    Thanks
     

    Tim Li

    MSDN Subscriber Support in Forum

    If you have any feedback on our support, please contact msdnmg@microsoft.com


    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    • Marked as answer by Tim Li Tuesday, September 29, 2009 3:02 AM
    Monday, September 7, 2009 8:28 AM

All replies

  • Hi Redd Green,

    Yes, we don't have a event in Excel Objece Model to track the Worksheet deleting, but we could have a work around, we could take use of Workbook.SheetActivate and Workbook.SheetDeactivate event, when a Worksheet is being deleted, it will fire a Workbook.SheetDeactivate event, and then a Workbook.SheetActivate event, in Workbook.SheetActivate event, if we test the Workbook.Worksheets.Count property we'll find that the count number is decreased by 1 when we test the same property in Workbook.SheetDeactivate.

    Thanks
     

    Tim Li

    MSDN Subscriber Support in Forum

    If you have any feedback on our support, please contact msdnmg@microsoft.com


    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    • Marked as answer by Tim Li Tuesday, September 29, 2009 3:02 AM
    Monday, September 7, 2009 8:28 AM
  • Hi Redd Green,

    I am writing to check the status of the issue on your side. Could you please let me know if the suggestion works for you or not? If you have any questions or concerns, please feel free to let me know. I will be more than happy to be of assistance.

    Thanks.

    Tim Li

    MSDN Subscriber Support in Forum

    If you have any feedback on our support, please contact msdnmg@microsoft.com


    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    Friday, September 11, 2009 6:49 AM
  • Tim,
           Thanks for the response and follow up.   I will try this out today, but it sounds like it will work.
    Regards,
    Mike
    Friday, September 11, 2009 3:12 PM