Home » excel » excel vba – VBA: Events for several dynamically added buttons

excel vba – VBA: Events for several dynamically added buttons

Posted by: admin April 23, 2020 Leave a comment

Questions:

I am adding several CommandButtons dynamically to my user form. To assign code, I used the answer of this question: Assign code to a button created dynamically

However, I need to determine which button has been clicked. They all do have different names. Therefore, my initial idea was to get the name of the clicked button in the CmdEvents_Click() procedure. However, I have not found a solution how to do that.

Does anyone have a solution how to trigger button specific events?

How to&Answers:
  • Add the Name of the new command e.g. like ctl_Command.Name = "name_" & i
  • Then in the CmdEvents_Click just use CmdEvents.Name.