Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8415439
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T01:26:51+00:00 2026-06-10T01:26:51+00:00

When I add a button or link to a spreadsheet the click event works.

  • 0

When I add a button or link to a spreadsheet the click event works. However when I save the spreadsheet, close it and reopen it the event doesn’t fire.

AddControl(xlApp, ((TaskPaneView)this.Parent).factory, "text", "A1");

public void AddControl(Microsoft.Office.Interop.Excel.Application xlApp, Microsoft.Office.Tools.Excel.ApplicationFactory factory, string controlText, string address)
{
    Microsoft.Office.Interop.Excel.Worksheet nativeWorksheet = xlApp.ActiveWorkbook.ActiveSheet;
    Microsoft.Office.Tools.Excel.Worksheet vstoWorksheet = factory.GetVstoObject(nativeWorksheet);
    var btn = new Microsoft.Office.Tools.Excel.Controls.Button();
    btn.Name = "link1";
    btn.Text = controlText;
    btn.Click += new EventHandler(btn_Click);
    vstoWorksheet.Controls.AddControl(btn, nativeWorksheet.Range[address], controlText);
}

void btn_Click(object sender, EventArgs e)
{

}

Is there a easy way to hook up the event again when the WorkBook is opened?

I’m thinking I will have to search the workbook for the buttons and AddHandler’s manually.

Edit: This is documented but there is no mention of the problem after closing the spreadsheet: Adding Controls to a Worksheet at Run Time in an Application-Level Project

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T01:26:53+00:00Added an answer on June 10, 2026 at 1:26 am

    enter image description here

    When a document is saved and then closed, all dynamic host controls are removed from the document. Only the underlying native Office objects remain behind..


    I might do it another way now, create VBA buttons with code to tap into the Add-In functionality:

    VBA code:

    Dim oAddin As COMAddIn
    Dim oCOMFuncs As Object
    Set oAddin = Application.COMAddIns(ExcelAddInNameSpace")
    Set oCOMFuncs = oAddin.Object
    oCOMFuncs.CallAFunctionOfAddIn
    

    Or another way using context menu’s (when over NamedRanges).


    More info from MSFT:

    But here comes the problem: if you save the workbook, open it on
    either a machine with the add-in intalled or a clean machine, the
    button doesn’t work this time!

    So we can see that adding controls onto document’s surface via add-in
    doesn’t make a lot of sense as the controls may loss its
    functionality. This is why we generally suggest to use Custom Task
    Pane instead of adding controls onto surface of document. Have a look
    at following documents:

    http://msdn.microsoft.com/en-us/library/aa942864.aspx

    http://msdn.microsoft.com/en-us/library/aa338197(v=office.12).aspx

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is it possible to add button click event by clicking design of axml? if
In below link there is add button which allows you to ADD multiple textbox
I add my page top link button like this: <a name=top></a> . . .
I am adding a KMZ file through network link on a ADD KMZ button's
When I click on Add button , the formAddNewRow form opens , but I
Hey, I want to add a button(link), that when clicked will filter the pagination
In following code, how can I add a button or a link that sorts
I have some pages with iframes in them. I want to add a link/button
I am trying to add a click event on the element that is return
Say I have two buttons Add Link and Add Text. The Add Link button

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.