PC Review


Reply
Thread Tools Rate Thread

a button on an excel cell

 
 
NA_AB
Guest
Posts: n/a
 
      6th Jan 2009
hey guys, just wanted to know if we can generate a button on an excel cell!
also, if we can, how to do we handle its actions like onButtonClick( ) etc?!
 
Reply With Quote
 
 
 
 
Mike H
Guest
Posts: n/a
 
      6th Jan 2009
Hi,

You can try this to get you going maybe.

View|Toolbars - Forms

On the toolbar click the button Icon and and the worksheet point-left click
and drag to get a button the size you want.

In the popup click 'NEW' and enter the following code

msgbox "Hello World"

Close VB editor and return to your sheet and click the button. All you need
to do now is add some meaningful code to that button.

Mike


"NA_AB" wrote:

> hey guys, just wanted to know if we can generate a button on an excel cell!
> also, if we can, how to do we handle its actions like onButtonClick( ) etc?!

 
Reply With Quote
 
Peter T
Guest
Posts: n/a
 
      6th Jan 2009
From your adjacent post I guess you mean you want a button on a sheet to
call code in your comaddin. You'd do that pretty much the same way as with
an Office.CommandBarButton. Ensure your addin has a reference to MSForms
object library and use WithEvents btn as MSForms.CommandButton.

Set c.btn = xlApp.ActiveWorkbook.Activesheet.OLEObjects(<name or
index>).Object

See VBA help how to add an ActiveX button to a worksheet.

Unlike the CommandBarButton which only exposes a click event, the
CommandButton exposes a range of events as well as click.

Regards,
Peter T

"NA_AB" <(E-Mail Removed)> wrote in message
news:149C3A70-DD19-46CC-8D53-(E-Mail Removed)...
> hey guys, just wanted to know if we can generate a button on an excel
> cell!
> also, if we can, how to do we handle its actions like onButtonClick( )
> etc?!



 
Reply With Quote
 
Peter T
Guest
Posts: n/a
 
      6th Jan 2009
> Ensure your addin has a reference to MSForms object library

Should have said "Microsoft Forms 2.0" (FM20.dll)

Also, perhaps I should have clarified I was talking about a button from the
'Control toolbox' toolbar (not the Forms toolbar)

Peter T

"Peter T" <peter_t@discussions> wrote in message
news:OiGYMr$(E-Mail Removed)...
> From your adjacent post I guess you mean you want a button on a sheet to
> call code in your comaddin. You'd do that pretty much the same way as with
> an Office.CommandBarButton. Ensure your addin has a reference to MSForms
> object library and use WithEvents btn as MSForms.CommandButton.
>
> Set c.btn = xlApp.ActiveWorkbook.Activesheet.OLEObjects(<name or
> index>).Object
>
> See VBA help how to add an ActiveX button to a worksheet.
>
> Unlike the CommandBarButton which only exposes a click event, the
> CommandButton exposes a range of events as well as click.
>
> Regards,
> Peter T
>
> "NA_AB" <(E-Mail Removed)> wrote in message
> news:149C3A70-DD19-46CC-8D53-(E-Mail Removed)...
>> hey guys, just wanted to know if we can generate a button on an excel
>> cell!
>> also, if we can, how to do we handle its actions like onButtonClick( )
>> etc?!

>
>



 
Reply With Quote
 
NA_AB
Guest
Posts: n/a
 
      7th Jan 2009
hey Mike, JBeaucaire, aamerrasheed, thank you guys but my exact dealing is
with the excel addin as peter has rightly stated! thanks Peter

n btw, peter, could you look into this once please..
http://www.microsoft.com/communities...sloc=en-us&p=1

 
Reply With Quote
 
NA_AB
Guest
Posts: n/a
 
      7th Jan 2009

how to generate the command button on the active cell?!?!
 
Reply With Quote
 
Peter T
Guest
Posts: n/a
 
      7th Jan 2009
I don't know the C# syntax but in VB/A -

Dim ole as Excel.OLEObject
With xlApp.ActiveCell
Set ole = xlApp.ActiveSheet.OLEObjects.Add("Forms.CommandButton.1", _
Left:=.Left, Top:=.Top, Width:=115#, Height:=24#)
End With
ole.Visible = True

' trap the button's events in a WithEvents class
Set c = New clsBtnEvents
Set c.btn = ole.Object

Regards,
Peter T


"NA_AB" <(E-Mail Removed)> wrote in message
news:918575BF-0023-4B5D-8628-(E-Mail Removed)...
>
> how to generate the command button on the active cell?!?!



 
Reply With Quote
 
NA_AB
Guest
Posts: n/a
 
      7th Jan 2009
thanks a ton peter... thanks for your help!

"Peter T" wrote:

> I don't know the C# syntax but in VB/A -
>
> Dim ole as Excel.OLEObject
> With xlApp.ActiveCell
> Set ole = xlApp.ActiveSheet.OLEObjects.Add("Forms.CommandButton.1", _
> Left:=.Left, Top:=.Top, Width:=115#, Height:=24#)
> End With
> ole.Visible = True
>
> ' trap the button's events in a WithEvents class
> Set c = New clsBtnEvents
> Set c.btn = ole.Object
>
> Regards,
> Peter T
>
>
> "NA_AB" <(E-Mail Removed)> wrote in message
> news:918575BF-0023-4B5D-8628-(E-Mail Removed)...
> >
> > how to generate the command button on the active cell?!?!

>
>
>

 
Reply With Quote
 
NA_AB
Guest
Posts: n/a
 
      7th Jan 2009
I'm really in need of some help, could you guide me through the way I can get
its C# equivalent code?
 
Reply With Quote
 
Peter T
Guest
Posts: n/a
 
      7th Jan 2009
I don't know C# so I'm afraid you'll have to translate the VB/A example I
gave you.

Regards,
Peter T

"NA_AB" <(E-Mail Removed)> wrote in message
news:9B4A614C-780C-483C-BC44-(E-Mail Removed)...
> I'm really in need of some help, could you guide me through the way I can
> get
> its C# equivalent code?



 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
button on excel cell NA_AB Microsoft Excel Programming 7 3rd Mar 2009 09:57 AM
How to set up the tab button to advance more than 1 cell in Excel. Marie Microsoft Excel Misc 1 17th Nov 2008 09:59 PM
How do I create a button within a cell in Excel? =?Utf-8?B?QXJteWR1ZGUyMDA1?= Microsoft Excel Misc 1 29th Jun 2007 09:20 PM
Excel - create button to replace cell content with cell value =?Utf-8?B?YmxhY2ttb3Q=?= Microsoft Excel Worksheet Functions 3 7th Dec 2005 05:10 PM
does excel know in which cell a button is located? Jim Microsoft Excel Programming 5 9th Oct 2005 06:22 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 06:34 PM.