ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   to add a button to the active excel cell! here's the way! (https://www.excelbanter.com/excel-programming/422216-add-button-active-excel-cell-heres-way.html)

NA_AB[_2_]

to add a button to the active excel cell! here's the way!
 
hey ppl n hi peter! at last, found a way out.

Range r = Connect.myApplication.ActiveCell;
Microsoft.Office.Interop.Excel.Worksheet theSheet =
(Microsoft.Office.Interop.Excel.Worksheet)Connect. myApplication.Worksheets.get_Item(1);
theSheet.Shapes.AddOLEObject("Forms.CommandButton. 1",
Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value,
"click_me", theSheet.get_Range(r, r).Left,theSheet.get_Range(r,
r).Top, theSheet.get_Range(r,
r).Width, theSheet.get_Range(r, r).Height);


Requires you to add MSForms 2.0, your addin should have a reference to
MSForms object library and use as MSForms.CommandButton.

NA_AB[_2_]

to add a button to the active excel cell! here's the way!
 
but hey, how to handle this button's click!? anybody help!!!

Peter T

to add a button to the active excel cell! here's the way!
 
Hello again,

As I tried to explain in my first reply in your thread "a button on an excel
cell" on 6-Jan, you do this in almost the same was as you handle the click
event of an Office.CommandBarButton. I think you already know how to do that
in C#, as you know I don't, but the main difference will be to declare as
MSForms.CommandButton.

Rather than starting a new thread try its better for all if you post
follow-ups in the original thread.

Regards,
Peter T

"NA_AB" wrote in message
...
but hey, how to handle this button's click!? anybody help!!!




abhi

to add a button to the active excel cell! here's the way!
 
On 9 Jan, 19:27, "Peter T" <peter_t@discussions wrote:
Hello again,

As I tried to explain in my first reply in your thread "a button on an excel
cell" on 6-Jan, you do this in almost the same was as you handle the click
event of an Office.CommandBarButton. I think you already know how to do that
in C#, as you know I don't, but the main difference will be to declare as
MSForms.CommandButton.

Rather than starting a new thread try its better for all if you post
follow-ups in the original thread.

Regards,
Peter T

"NA_AB" wrote in message

...

but hey, how to handle this button's click!? anybody help!!!


hey dude, cud find a way out atlast: :)

Range r = Connect.myApplication.ActiveCell;
Worksheet sht = (Worksheet)
Connect.myApplication.ActiveSheet;
Shape btn = sht.Shapes.AddOLEObject("Forms.CommandButton.
1", Missing.Value, Missing.Value, Missing.Value, Missing.Value,
Missing.Value, Missing.Value,
sht.get_Range(r,
r).Left, sht.get_Range(r, r).Top, 60,20);//sht.get_Range(r,r).Width,
sht.get_Range(r, r).Height);
OLEObject obj1 = (OLEObject)(sht.OLEObjects
("CommandButton1"));
MSForms.CommandButton mbtn = (MSForms.CommandButton)
(obj1.Object);
mbtn.Caption = "click me";
mbtn.Click += new
Microsoft.Vbe.Interop.Forms.CommandButtonEvents_Cl ickEventHandler
(main_form_click);


All times are GMT +1. The time now is 12:27 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com