Export (0) Print
Expand All

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 Button AddButton(
	Range range,
	string name


Type: Range

A Range that provides the bounds for the control.

Type: System.String

The name of the control that can be used to index the control in the ControlCollection instance.

Return Value

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


The name or range argument is null, 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 void ExcelRangeAddButton()

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

Community Additions

© 2014 Microsoft