Search code examples
c#excelvisual-studiovsto

Excel workbook created with VSTO does not execute buttons after save


So I did the following steps:

  1. Prepared an Excel VSTO Add-in, where the add-in creates two excel sheets and positions several buttons on those two sheets. Each button can have trivial or non-trivial action assigend. For example, button1 will simply increase the font size, while button2 will use the VSTO c# code to initialize several classes, process the data and print output to sheet. It all works when running excel from the Visual Studio.
  2. I then save the woorkbook (tried also saving as "with macro enabled").
  3. Close excel. Close Visual Studio.
  4. Reopen workbook with Excel.
  5. Click on any button and nothing happens -> like there is no functionality attached to the buttons.

Is this known limitation or am I doing something wrong?

My goal is to use VSTO Add-in to create a functional sheet (add formatting, add buttons,...) that later anybody could open without actually installing the Add-in. I am now doubting that is even possible.


Solution

  • The actions for the buttons are part of the add-in, not part of the sheet.

    When you add a button, that is changing the sheet itself. When you add an event handler to the button, that is calling code in the add-in, not the sheet.

    You need the add-in to look for the buttons when you open the document, and then attach the event handlers at that point.