none
How can I prevent deleting or renaming a worksheet using VSTO? RRS feed

  • Question

  • How can I prevent deleting or renaming a worksheet with predefined name  using VSTO?

    I am creating a Excel AddIn using VSTO, C#?

    Thursday, October 15, 2015 9:15 AM

All replies

  • >>>How can I prevent deleting or renaming a worksheet with predefined name using VSTO?

    Could you tell us what kind of solutlion you was developing, Document-level customizations or VSTO Add-ins?

    Document-level customizations are associated with a specific document,VSTO Add-ins are associated with the application itself.

    You could protect Workbook to prevent deleting or renaming a worksheet, but it will cause workbook cannot be modified at the same time.

    this.Application.ActiveWorkbook.Protect(Type.Missing, true, false);

    For more information, click here to refer about How to: Programmatically Protect Workbooks

    Monday, October 19, 2015 8:19 AM
  • Thanks David for your response.

    I am creating a VSTO AddIns. 

    In my case protecting workbook is not an solution.

    Is there any other solution like revert once found that a filename having predefined name will be renamed back to original name etc.

    Monday, October 19, 2015 8:33 AM
  • Hi Animesh

    You might want to ask in the Excel for Developers forum how the Excel specialists handle something like this...

    Replying, though, to "reverting": You can add a CustomXMLPart to the workbook with any well-formed XML you prefer to store information you want to "enforce" in the workbook. Then monitor certain events, such as saving or printing. Check the settings and reset any changes before allowing the action (save, print, whatever) to procede.


    Cindy Meister, Office Developer/Word MVP, <a href="http://blogs.msmvps.com/wordmeister"> my blog</a>

    Monday, October 19, 2015 1:06 PM
    Moderator
  • Not a real answer but i think these two links can give you some interesting insights :

    http://stackoverflow.com/questions/2536876/how-to-effectively-use-workbookbeforeclose-event-correctly

    and

    https://social.msdn.microsoft.com/Forums/vstudio/en-US/5d778219-a92f-4a38-8ea7-fd1bc6bc7fb8/workbookbeforeclose-event-does-not-fire?forum=vsto
    Saturday, October 24, 2015 5:55 PM