Home |
Search |
Today's Posts |
|
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
a button on an excel cell
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?! |
#2
Posted to microsoft.public.excel.programming
|
|||
|
|||
a button on an excel cell
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?! |
#3
Posted to microsoft.public.excel.programming
|
|||
|
|||
a button on an excel cell
Use the Controls Toolbar Button to draw a command button where you'd like. Right-click on the button and View Code to see where the macro code should go. It can do anything you'd like. Or, use the Forms Toolbar Button to draw a Forms Button, and right-click on it to assign a macro you've already created earlier. -- JBeaucaire ------------------------------------------------------------------------ JBeaucaire's Profile: http://www.thecodecage.com/forumz/member.php?userid=73 View this thread: http://www.thecodecage.com/forumz/sh...ad.php?t=46945 |
#4
Posted to microsoft.public.excel.programming
|
|||
|
|||
a button on an excel cell
Hi,
On developer tab, you have an option "Insert Control" option, and there you can find "Form Controls" You can add buttons and other control buttons from there. As soon as you create a button, it will prompt to select the macro. 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?! |
#5
Posted to microsoft.public.excel.programming
|
|||
|
|||
a button on an excel cell
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" wrote in message ... 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?! |
#6
Posted to microsoft.public.excel.programming
|
|||
|
|||
a button on an excel cell
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 ... 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" wrote in message ... 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?! |
#7
Posted to microsoft.public.excel.programming
|
|||
|
|||
a button on an excel cell
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 |
#8
Posted to microsoft.public.excel.programming
|
|||
|
|||
a button on an excel cell
how to generate the command button on the active cell?!?! |
#9
Posted to microsoft.public.excel.programming
|
|||
|
|||
a button on an excel cell
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.CommandBut ton.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" wrote in message ... how to generate the command button on the active cell?!?! |
#10
Posted to microsoft.public.excel.programming
|
|||
|
|||
a button on an excel cell
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.CommandBut ton.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" wrote in message ... how to generate the command button on the active cell?!?! |
#11
Posted to microsoft.public.excel.programming
|
|||
|
|||
a button on an excel cell
I'm really in need of some help, could you guide me through the way I can get
its C# equivalent code? |
#12
Posted to microsoft.public.excel.programming
|
|||
|
|||
a button on an excel cell
Peter T,
I'm having some problems with your example code; With this in a class module called "clsBtnEvents": Option Explicit Private WithEvents mbtn As MSForms.CommandButton Friend Property Set Button(ByRef btn As MSForms.CommandButton) Set mbtn = btn End Property Private Sub mbtn_Click() MsgBox "Button with caption """ & mbtn.Caption & """ was clicked." End Sub An this in a normal code module: Option Explicit Dim objBtnEventHandlers() As New clsBtnEvents Sub InsertButtonInActiveCell() Static slngBtnNum As Long Dim ole As Excel.OLEObject Dim btn As MSForms.CommandButton Dim appXl As Excel.Application: Set appXl = ThisWorkbook.Application If Not ActiveCell Is Nothing _ And TypeOf ActiveSheet Is Worksheet Then With appXl.ActiveCell Set ole = appXl.ActiveSheet.OLEObjects.Add( _ "Forms.CommandButton.1", _ Left:=.Left, Top:=.Top, _ Width:=.Width, Height:=.Height) End With With ole slngBtnNum = slngBtnNum + 1 .Object.Caption = "Button " & CStr(slngBtnNum) ReDim Preserve objBtnEventHandlers(1 To slngBtnNum) Set objBtnEventHandlers(slngBtnNum).Button = .Object End With End If End Sub I can't seem to trap the click event, also the static variable slngBtnNum doesn't increase resulting all buttons having the name "Button 1".. I've tried to figure out whats the problem, but can't seem to find it.. Do you see any obvious mistakes? I've also found that I cannot set breakpoints below the line that adds the button to the sheet, I get the message "Can't enter break mode at this time". best regards Peder Schmedling On Jan 7, 11:51*am, "Peter T" <peter_t@discussions wrote: Dim ole as Excel.OLEObject With xlApp.ActiveCell Set ole = xlApp.ActiveSheet.OLEObjects.Add("Forms.CommandBut ton.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 |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
How to set up the tab button to advance more than 1 cell in Excel. | Excel Discussion (Misc queries) | |||
How do I create a button within a cell in Excel? | Excel Discussion (Misc queries) | |||
Linking a VBA button to Excel cell | Excel Programming | |||
Excel - create button to replace cell content with cell value | Excel Worksheet Functions | |||
does excel know in which cell a button is located? | Excel Programming |