title: Insert a TextBox and set the formula
body: <p>In VBA for Excel 2007, I want to add a textbox to the active sheet and set its formula to a cell. My problem is that the <code>AddTextbox</code> function returns an object with typename <code>Shape</code>, not <code>TextBox</code>, so it does not have a <code>Formula</code> property to set. Instead, I ended up looping through all the textboxes to find the right one, then set its <code>Formula</code>. Is there a better way to do this?</p>
  
  <pre><code>Sub insertTextBoxWithFormula()
      Set newTextBox = ActiveSheet.Shapes.AddTextbox(msoTextOrientationHorizontal, 200, 200, 150, 150)
      newTextBox.Name = "New TextBox"
      'newTextBox.Formula = "=$A$1" 'This is what I wanted to do
  
      'This is what I did instead
      For Each CurrentTextBox In ActiveSheet.TextBoxes
          If CurrentTextBox.Name = "New TextBox" Then
              CurrentTextBox.Formula = "=B3"
              CurrentTextBox.Name = "Finished TextBox"
          End If
      Next CurrentTextBox
  End Sub
  </code></pre>