title: Creating form programmatically in the module using vba
body: <p>I want to create a user form in the module using VBA programmatically. I am a novice and inexperienced so I have tried couple of examples, but they are not fulfilling my requirements.</p>
  
  <p>I just want macro that</p>
  
  <ul>
  <li>creates a user form within a module using VBA</li>
  <li>has a ListBox with some data</li>
  <li>has a CommandButton with a listener</li>
  </ul>
  
  <p>Here is the code which I used </p>
  
  <pre><code>Option Explicit
  
  Sub MakeuserForm()
  'Dim CommandButton1 As MsForms.CommandBarButton
  'Dim ListBox1 As MsForms.ListBox
  Dim UserForm1 As VBComponent
  
  Set UserForm1 = ActiveWorkbook.VBProject.VBComponents.Add(vbext_ct_MSForm)
  With UserForm1
  .Properties("Height") = 100
  .Properties("Width") = 200
  On Error Resume Next
  .Name = "My Form"
  .Properties("Caption") = "This is your user form"
  End With
  ShowForm
  End Sub
  
  Sub ShowForm() 
  NewForm.Show 
  End Sub 
  </code></pre>
  
  <p>Now I don't know how to add ListBox and button to the form with a listener.</p>