title: How to create and set a ActiveX Control CommandButton as a variable Excel VBA
body: <p>I am trying to Create a New ActiveX Control CommandButton with Excel VBA. I have a loop VBA which has worked in the past, theFile1.1.xlsm has the master list of the workbooks. I need to add a CommandButton to ~3200 workbooks, so I will be using the Do-Loop macro. Here is the Loop code for reference.</p>
  
  <pre><code>Sub Macro2() 
  
  Application.ScreenUpdating = False
  
  Dim sFile As String
  Dim wb As Workbook
  Dim FileName1 As String
  Dim FileName2 As String
  Dim wksSource As Worksheet
  Const scWkbSourceName As String = "theFILE 1.1.xlsm"
  
  Set wkbSource = Workbooks(scWkbSourceName)
  Set wksSource = wkbSource.Sheets("Sheet1") ' Replace 'Sheet1' w/ sheet name of SourceSheet
  
  Const wsOriginalBook As String = "theFILE 1.1.xlsm"
  Const sPath As String = "E:\ExampleFolder\"
  
  SourceRow = 5
  
  Do While Cells(SourceRow, "D").Value &lt;&gt; ""
  
      Sheets("Sheet1").Select
  
      FileName1 = wksSource.Range("A" &amp; SourceRow).Value
      FileName2 = wksSource.Range("K" &amp; SourceRow).Value
  
      sFile = sPath &amp; FileName1 &amp; "\" &amp; FileName2 &amp; ".xlsm"
  
      Set wb = Workbooks.Open(sFile)
  
          ''insert code for loop operation
  
      '''CLOSE WORKBOOK W/O BEFORE SAVE
      Application.EnableEvents = False
      ActiveWorkbook.Save
      ActiveWorkbook.Close
      Application.EnableEvents = True
  
  SourceRow = SourceRow + 1
  
  Loop
  
  End Sub
  </code></pre>
  
  <p>I would like to have the button set as a Variable (i think), so I can edit the formatting/properties and hopefully add a macro to the button later.</p>
  
  <pre><code>    Dim buttonControl As MSForms.CommandButton
  
      Set buttonControl = _
          ActiveSheet.OLEObjects.Add(ClassType:="Forms.CommandButton.1", _
          Link:=False, _
          DisplayAsIcon:=False, _
          Left:=1464, Top:=310, Width:=107.25, Height:=30)
  
      With buttonControl.Opject
          .Caption = "OPEN FOLDER"
          .Name = "cmd_OPEN_FOLDER"
  
      End With
  </code></pre>
  
  <p>I have a 'Run-time error 13: Type Mismatch' error. I am unsure why, because a 'CommandButton1' is created in the correct place.</p>