none
Can't delete Worksheet from VSTO Excel project RRS feed

  • Question

  • Hi, my development environment is:

    • Windows 7 64-bit
    • .NET Framework 4.0
    • Office Professional Plus 2013
    • Visual Studio Professional 2013
    • Developing a document-level customization Excel template

    I no longer need one of the worksheets in the template, so I deleted it. After that, I opened the workbook from within VS so it knows I deleted such worksheet (I also tried solving my problem by deleting it from within VS with the same result).

    As far as I remember, this is the way to go when deleting a worksheet. In particular, opening the workbook from within VS so it updates the workbook design. My project compiles without errors, but when I debug it, I get the following error:

    Cannot load type [Workbook Name].[WorksheetName], where [WorksheetName] is the name of the worksheet I deleted. The project doesn't load because of this error. I went to Class View and class [WorksheetName] wasn't in the project. Also sought it in F2, My Solution, and it didn't appear there either and even sought for that file in Windows Explorer. I'm very confused as I don't understand why is VS thinking that class still exists.

    Any ideas of what might be going on here? I've been having crashes with Excel, and some other errors like:

    • VS complaining there're two workbooks with the same name open when creating a brand new Excel workbook (document-level customization), while having Excel closed.
    • Having the Global class returning nulls when referencing a worksheet (Globals.[WorksheetName] returns Nothing). Of course, the worksheet exists and is part of the workbook in this case.

    I'm reinstalling Office and will run Windows Update, but would like to know if there's any advise around there.

    Update: VS is not properly creating new worksheets. For example, the Initialize macro never gets called and therefore Globals.[WorksheetName] returns Nothing.

    Thanks in advance,

    Carlos


    • Edited by Carlos Mallen Saturday, January 16, 2016 5:38 PM added more information
    Saturday, January 16, 2016 2:01 AM

Answers

  • Hi Edward,

    My bad, I had installed a prior version of the project. This was causing VS not to forget deleted worksheets and not to recognize new ones (i.e., it was using the prior version of the manifest to check if all components were in the file). After removing it from Programs and Features, everything worked OK.

    Thanks for your time,

    Carlos

    Tuesday, January 26, 2016 1:47 PM

All replies

  • Hi Carlos,

    I tried to reproduce the issue but it is not produced. I tried to produce it by different ways but every time it work correctly on my side.

    As your problem is deleted sheet and there is no error in your code so you can try to execute the same code with creating a new fresh project. It’s a new project so there is a no problem like deleted worksheet. You can try and let us know whether it is worked or not.

    Best Regards,

    Edward


    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.


    Monday, January 18, 2016 8:00 AM
  • Hi Edward,

    Thanks for your response. Over the weekend I tried that and still got some errors (sorry I do not remember them exactly) and as I have been having problems with brand new Excel projects, I think something went wrong with VS, Office, or the VSTO runtime. I will try again this week.

    In this particular case, VS does not forget deleted worksheets (i.e., sends an error stating the project is missing such component) and does not recognize new worksheets (i.e., they are not even initialized).

    Regards,

    Carlos

    Monday, January 18, 2016 1:43 PM
  • Hi Carlos,

    >> as I have been having problems with brand new Excel projects, I think something went wrong with VS, Office, or the VSTO runtime

    Do you mean you could reproduce your issue with a new project? I suggest you test in other pcs with the same pcs to check whether it could be reproduced.

    Since I could not reproduce your issue at my side, I agree with you that it might be something wrong with your VS, Office, or VSTO runtime. It seems you have reinstalled Office, if so, I suggest you try steps below:
    1. Create a new project under C# template and test whether it could work.
    2. Repair or reinstall your VS.

    Best Regards,

    Edward


    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 19, 2016 5:40 AM
  • Hi Edward,

    My bad, I had installed a prior version of the project. This was causing VS not to forget deleted worksheets and not to recognize new ones (i.e., it was using the prior version of the manifest to check if all components were in the file). After removing it from Programs and Features, everything worked OK.

    Thanks for your time,

    Carlos

    Tuesday, January 26, 2016 1:47 PM
  • Hi Carlos,

    Thanks for sharing the solution.

    I am glad you found the root cause, and resolved it. I suggest you mark your reply as answer to close this thread, and then others who run into the same issue would find the solution easily.

    Best Regards,

    Edward


    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, January 27, 2016 3:11 AM