更新:2007 年 11 月
在工作表中的指定范围添加一个新的 Button 控件。
命名空间:  Microsoft.Office.Tools.Excel
程序集:  Microsoft.Office.Tools.Excel.v9.0(在 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, _
    name)
public Button AddButton(
    Range range,
    string name
)
参数
- range 
 类型:Microsoft.Office.Interop.Excel.Range- 提供控件的边界的 Range。 
- name 
 类型:System.String- 可用于索引 ControlCollection 实例中控件的控件名称。 
返回值
类型:Microsoft.Office.Tools.Excel.Controls.Button
添加到 ControlCollection 实例的 Button 控件。
异常
| 异常 | 条件 | 
|---|---|
| ArgumentNullException | 名称参数或范围参数为 nullnull 引用(在 Visual Basic 中为 Nothing),或者名称参数长度为零。 | 
| ControlNameAlreadyExistsException | ControlCollection 实例中已存在一个同名控件。 | 
| InvalidRangeException | 指定的范围无效。不能使用多区域范围。该范围应与 ControlCollection 实例同在一个工作表中。 | 
备注
使用 AddButton 方法可以将 Button 对象添加到 ControlCollection 的末尾。若要移除以前以编程方式添加的 Button,请使用 Remove() 方法。
在调整范围的大小时,控件会自动调整其自身的大小。
示例
下面的代码示例将一个 Button 控件添加到单元格“A1”,然后向该按钮添加文本。
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";
}
权限
- 对直接调用方的完全信任。此成员不能由部分信任的代码使用。有关更多信息,请参见通过部分受信任的代码使用库。