ControlCollection.AddButton Method (, String) (2007 System)

Adds a new Button control to the worksheet at the range specified.

Namespace:  Microsoft.Office.Tools.Excel
Assembly:  Microsoft.Office.Tools.Excel.v9.0 (in Microsoft.Office.Tools.Excel.v9.0.dll)


Public Function AddButton ( _
    range As Range, _
    name As String _
) As Button
Dim instance As ControlCollection 
Dim range As Range 
Dim name As String 
Dim returnValue As Button 

returnValue = instance.AddButton(range, _
public Button AddButton(
    Range range,
    string name
Button^ AddButton(
    Range^ range, 
    String^ name
public function AddButton(
    range : Range, 
    name : String
) : Button


  • range
    Type: Range

    A Range that provides the bounds for the control.

Return Value

Type: Microsoft.Office.Tools.Excel.Controls.Button
The Button control that was added to the ControlCollection instance.


Exception Condition

The name or range argument is nulla null reference (Nothing in Visual Basic), or the name argument has zero length.


A control with the same name is already in the ControlCollection instance.


The range that was specified is not valid. Multi-area ranges cannot be used. The range should be on the same worksheet as the ControlCollection instance.


The AddButton method enables you to add Button objects to the end of the ControlCollection. To remove a Button that was previously added programmatically, use the Remove method.

The control automatically resizes when the range is resized.


The following code example adds a Button control to cell A1, and then adds text to the button.

Private Sub ExcelRangeAddButton()

    Dim Button1 As Microsoft.Office.Tools.Excel. _
      Controls.Button = Me.Controls.AddButton( _
      Me.Range("A1"), "Button1")
    Button1.Text = "OK" 

End Sub
private void ExcelRangeAddButton()

    Microsoft.Office.Tools.Excel.Controls.Button button1 =
        this.Controls.AddButton(this.Range["A1", missing], "button1");
    button1.Text = "OK";

.NET Framework Security

See Also


ControlCollection Class

ControlCollection Members

AddButton Overload

Microsoft.Office.Tools.Excel Namespace