title: Adding Click Behaviour to Dynamically Created Form Control Button with VBA in Excel
body: <p>As a follow-up to <a href="https://stackoverflow.com/questions/10822450/copy-elements-from-one-page-to-another-in-multipage-with-vba-in-excel">this question</a>, where a userform allows the creation of x # of tabs in a multipage during runtime, each with the same controls, I am wondering how to set the .OnClick behaviour of the buttons. I am trying to achieve this with the following code:</p>
  
  <pre><code>For Each ctl In MultiPage1.Pages(NumSegs - 1).Controls
      If TypeOf ctl Is MSForms.CommandButton Then
          ctl.Name = "Segment" &amp; NumSegs &amp; "Button"
          ctl.OnClick = "Span_Form_Click_Handler"
      End If
  Next
  </code></pre>
  
  <p>But of course there doesn't seem to be a .OnClick method...</p>