Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
HOW CAN I WRITE A CODE TO COMMANDBUTTON ADDED AT RUNTIME?
After I add a CommandButton control to a UserForm by Add method, how can I
write a code to that CommandButton? -- Kozete |
#2
Posted to microsoft.public.excel.programming
|
|||
|
|||
HOW CAN I WRITE A CODE TO COMMANDBUTTON ADDED AT RUNTIME?
Command buttons from the forms toolbar are attached to the macro through an
assignment dialog box at the time the marcro is created, or by calling the dialog box at a later time, if required. These cannot be easily connected with VBA. Command buttons from the Control Tool box have a click event code. There are two methods to tie the macro to the button click event. One is to put the code directly into the click event by right clicking the button in design mode and then click view code. This will automatically display the first and last line of the click event macro and the user can fill in the middle part. The second method is to put the executable code in the standard project code module and just use the click event to call that code. For example your code in the standard module is Macro1, this would be the code behind the command button: Private Sub CommandButton1_Click() Macro1 End Sub Macro1 would then execute from the standard module. But in any case, The code to enact the command button must be in the command button attributes. "Kozete" wrote: After I add a CommandButton control to a UserForm by Add method, how can I write a code to that CommandButton? -- Kozete |
#3
Posted to microsoft.public.excel.programming
|
|||
|
|||
HOW CAN I WRITE A CODE TO COMMANDBUTTON ADDED AT RUNTIME?
You could theoretically write code to write code, but you will probably run
into problems quickly (virus detection may think it's a virus and quarantines the workbook. The code persists, so it needs to be cleaned up and rebuilt. The macro is reformed as a string, making edits a pain). John Walkenbach has a nifty macro to do this using a class, avoiding the problems above. http://www.j-walk.com/ss/excel/tips/tip44.htm To delve into this more, if you have access to it, check out Francesco Balena's Programming Visual Basic 6. Balena's one of the best authors out there and he has a chapter in his book devoted dynamically created forms and events. -- Tim Zych www.higherdata.com Compare data in worksheets and find differences with Workbook Compare A free, powerful, flexible Excel utility "Kozete" wrote in message ... After I add a CommandButton control to a UserForm by Add method, how can I write a code to that CommandButton? -- Kozete |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
Textbox added to Form at runtime too small, can't control size andchange event won't trigger | Excel Worksheet Functions | |||
Click events not working when added during runtime | Excel Programming | |||
Manipulate Controls added at runtime | Excel Programming | |||
MatchEntry for combobox added during runtime | Excel Programming | |||
add event to controls added in runtime | Excel Programming |