none
Problems deleting Excel worksheets RRS feed

  • Question

  • I have a workbook project with one sheet, sheet1. I begin the code by looping the sheets, checking if there is more than one sheet and if, then deleting all that are not named sheet1. Should be totally needless operation, right? Well, sometimes it decides there is more worksheets which makes no sense to me. Then I try to delete the ones there are and - boom - nothing to delete -> Throws an error.

    Is this a VSTO issue or is it more likely it is some cache error with the environment?

    Monday, January 20, 2014 11:35 PM

Answers

  • Hi,

    What's the error message do you get?

    Since you said you have a workbook project, do you mean that it is a Document-level Excel add-in project?

    If so, you could try to open the workbook in bin->Debug folder of your project folder and delete other worksheets expected "Sheet1" manually. If you could delete it successfully, the issue may be related to your code. If not, it may be related to the workbook you are using.

    Since we cannot repro your issue, would you mind sharing your sample document and code by SkyDrive to help us to troubleshoot?


    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.

    Tuesday, January 21, 2014 1:03 PM
    Moderator

All replies

  • Hello KilpAr,

    It looks like Excel doesn't allow to remove the last worksheet from a workbook. You can check it out in VBA.

    As you may see, the issue is not related to VSTO at all. I'd recommend asking such questions in the Excel for Developers forum thread.

    Tuesday, January 21, 2014 12:50 PM
  • Hi,

    What's the error message do you get?

    Since you said you have a workbook project, do you mean that it is a Document-level Excel add-in project?

    If so, you could try to open the workbook in bin->Debug folder of your project folder and delete other worksheets expected "Sheet1" manually. If you could delete it successfully, the issue may be related to your code. If not, it may be related to the workbook you are using.

    Since we cannot repro your issue, would you mind sharing your sample document and code by SkyDrive to help us to troubleshoot?


    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.

    Tuesday, January 21, 2014 1:03 PM
    Moderator