WorkbookBase.CommandBars 属性
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
获取一个 Microsoft.Office.Core.CommandBars 对象,该对象表示 Microsoft Office Excel 命令栏。
public Microsoft.Office.Core.CommandBars CommandBars { get; }
属性值
一个CommandBars对象,它表示 Microsoft Office Excel 命令栏。
示例
下面的代码示例使用 CommandBars 属性删除所有不可见的自定义命令栏。 此示例假设当前工作簿嵌入到另一个应用程序中。
此示例适用于文档级自定义项。
private void WorkbookCommandBars()
{
if (this.CommandBars != null)
{
for (int i = 1; i <= this.CommandBars.Count; i++)
{
if (!this.CommandBars[i].BuiltIn &&
!this.CommandBars[i].Visible)
{
this.CommandBars[i].Delete();
}
}
}
else
{
MessageBox.Show("This workbook must be opened in another " +
"application to use the CommandBars property.");
}
}
Private Sub WorkbookCommandBars()
If Not (Me.CommandBars Is Nothing) Then
Dim i As Integer
For i = 1 To Me.CommandBars.Count
If Not Me.CommandBars(i).BuiltIn AndAlso Not _
Me.CommandBars(i).Visible Then
Me.CommandBars(i).Delete()
End If
Next i
Else
MsgBox("This workbook must be opened in another " & _
"application to use the CommandBars property.")
End If
End Sub
注解
如果工作簿嵌入到另一个应用程序中并通过双击工作簿由用户激活,则使用带有工作簿对象的属性将返回在另一个应用程序中可用的 Excel 命令栏集。 在所有其他时间,将此属性与工作簿对象结合使用将返回 null 。 不能通过编程方式来返回附加到工作簿的命令栏集。 命令栏与应用程序相关联,而不是与工作簿相关联。 此属性存在于工作簿中,因此在 Excel 不是应用程序时可以访问 Excel 应用程序命令栏。