title: Reference to Command Buttons Added During Runtime with VBA in Excel
body: <p>During runtime, the user is able to add any number of ActiveX command buttons to Sheet 1. I need to have a reference to these new buttons with VBA, but am not sure how.</p>
  
  <p>I know a logical progression which the button names will exhibit: ex.</p>
  
  <p>(Node#x2)-2=CommandButton#=i</p>
  
  <p>I need to somehow refer to these newly created buttons, I'm thinking is along the lines of this:</p>
  
  <pre><code>Sheet1.Controls("CommandButton" &amp; i).Select
  </code></pre>
  
  <p>If anyone knows the correct syntax or an alternate method please advise!</p>
  
  <p><strong>UPDATE</strong></p>
  
  <pre><code>Public Sub Node_Button_Duplication()
  '
  'Comments: Copies and pastes Node 1's button to the appropriate column
  
  ' Copy Node 1 button and paste in appropriate location
      ActiveSheet.Shapes("CommandButton1").Select
      Selection.Copy
      Cells(5, 10 + 7 * (NumNodes - 1) - 1).Select
      ActiveSheet.Paste
      Selection.ShapeRange.IncrementLeft 47.25
      Selection.ShapeRange.IncrementTop -13.5
  
  
  End Sub
  </code></pre>
  
  <p><strong>Follow-Up</strong></p>
  
  <pre><code>Public Sub Node_Button_Duication()
  '
  'Comments: Copies and pastes Node 1's button to the appropriate column
  
  Dim shp As Shape
  
  ' Copy Node 1 button and paste in appropriate location
      ActiveSheet.Shapes("CommandButton1").Select
      Selection.Copy
      Cells(5, 10 + 7 * (NumNodes - 1) - 1).Select
      ActiveSheet.Paste
      Selection.ShapeRange.IncrementLeft 47.25
      Selection.ShapeRange.IncrementTop -13.5
  
      Debug.Print Selection.Name
  
      Set shp = ActiveSheet.Shapes(Selection.Name)
  
      With shp.OLEFormat.Object.Object
          .Caption = "Test"
          .Left = 15
          .Top = 15
      End With
  
  End Sub
  </code></pre>
  
  <p>This gives me a Run-time error "438: Object doesn't support this property or method. I don't particularly understand </p>
  
  <pre><code>shp.OLEFormat.Object.Object
  </code></pre>