Add button to worksheet cell

G

Guest

Hi,

I am able to add a button in an excel worksheet cell in C# code. Now I want
to handle its click event in the C# itself.

Here is the code I have tried:

Excel.Buttons buttons = activeSheet.Buttons(System.Reflection.Missing.Value)
as Excel.Buttons;
Excel.Button button = null;
button = buttons.Add(5, 5, 100, 20);
button.Caption = "Trend Chart";

Now, there is one property of button class named ".OnAction". I guess we can
only define the macro name in this.
Kindly let me know how to handle its click event in C# instead of calling
macro?

Thanks,
Sunil
 
G

Guest

I hope I understand correctly.
If you go into design mode and you double click the button.It will give you
a on click event. Then add code.
G
 
G

Guest

Hi,

We are adding button programmatically to the Excel Worksheet. So, button
will be available only at run time. There is no such option to double click
it and write desired code for the click action.

Thanks,
Crusader
 
W

Waseem Chishti

HI Crusader;

I am currently facing the same problem. I managed to add buttons in
excel worksheet programmatically, but could not set what method to call
on OnAction. I would highly appreciate if you share the solution with
me if you found one. I searched the net but was unable to find a
solution.

Waseem
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top