![]() |
![]() |
|
|||||||
| Excel Questions All Excel/VBA questions - formulas, macros, pivot tables, general help, etc. Please post to this forum in English only. |
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
New Member
Join Date: Mar 2002
Posts: 9
|
Once you add a control to a userform during runtime, how to activate/access the events such as _click()?
These controls work at runtime, such as a checkbox toggling on and off but I can not program an event. Thanks for any help |
|
|
|
|
|
#2 |
|
MrExcel MVP
Join Date: Feb 2002
Location: Bogota, Colombia
Posts: 11,927
|
You can add code at run time as well. You need to set a reference to Visual Basic Extensibility, but, I saw, I think Damon Ostrander, make a suggestion, like this:
If you know you MAY add a checkbox at run time, and you need the_Click() sub, you can create the Sub at Design time with the name of the control you will have at run time, that way, if the control is added, it'll have its _Click() event. |
|
|
|
|
|
#3 |
|
New Member
Join Date: Mar 2002
Posts: 9
|
Juan: Thanks for looking into this.
** I am not having any trouble adding a control, such as a checkbox, at run time. I am able to add the control with the following statements. ** Dim TestCheckbox As Control Sub Private Whatever() Set TestCheckbox = _ Controls.Add("Forms.Checkbox.1", _ "TestCheckbox", True) End Sub ** Now if I add the following sub routine, it is treated as a standalone subroutine, not an event associated with the checkbox: ** Sub Private TestCheckbox_Click() End Sub ** To further complicate matters, I tried the following test. ** Dim WithEvents SingleButton As CommandButton Sub Private Whatever() Set SingleButton = _ Controls.Add("Forms.CommandButton.1", _ "SingleButton", True) End Sub Sub Private SingleButton_Click() SingleButton.Cpation = "Changed" End Sub ** This works. The VBA compiler will allow "Dim WithEvents SingleButton As CommandButton" but not Dim WithEvents SingleButton As CheckBox" ** Any clues? [ This Message was edited by: LaShark on 2002-03-27 08:10 ] [ This Message was edited by: LaShark on 2002-03-27 08:21 ] |
|
|
|
![]() |
| Bookmarks |
| Thread Tools | |
| Display Modes | |
|
|