excel vba - Adding Code to a Command Button that was dynamically added to a frame in a user code -
This is a Vibe question: I got this question: "Adding control over a frame in Excel User with VBA" and my user It was used to add commandbutan to the frame in the form. Since I have added four commandbots, I participated in a loop code and with
... .name = "command button" & amp; X Give each command button your name; I included my code macro for every CommandButton (because I gave them names I know that each is CB name) but when I click on the button Click, nothing happens.
Or, if someone could explain to me how to use the code to control a form in a frame, I can solve my problem in a different way.
thanks,
Michael
It seems that The events are controlled only for the object variables which were declared when the VBA program has been compiled (i.e. in design time.) When you create objects in dynamic form (ie in run-time) then you have the right object variable which To be declared, the references to those items will be handed out.
According to your example, in the module which is related to your UserForm , you will need:
btn1 People WithEvents MSForms.CommandButton People WithEvents as btn2 MSForms.CommandButton Public WithEvents as MSForms.CommandButton P. btn3 ublic withEvents btn4 MSForms.CommandButton as ( MSForms variable Type prefix might not be extremely necessary)
Then with your in control you can get one of the variables which ends up being quite dirty Everyone Iyntrn statement to the need to allocate
better solutions :.
- Create maximum number of possible buttons at design time and toggle the
visibleproperty to show the right people - If the function of each button Use some property of the
CommandButtonobject (such ascaptionproperty,tag) to determine if it can be set to run-time. Code> property) and then the event handler for that button, depending on the property - By changing the UI and clicking the
list boxorcombo box
Comments
Post a Comment