Share via


WorkbookBase.CommandBars 属性

定义

获取一个 Microsoft.Office.Core.CommandBars 对象,该对象表示 Microsoft Office Excel 命令栏。

public:
 property Microsoft::Office::Core::CommandBars ^ CommandBars { Microsoft::Office::Core::CommandBars ^ get(); };
public Microsoft.Office.Core.CommandBars CommandBars { get; }
member this.CommandBars : Microsoft.Office.Core.CommandBars
Public ReadOnly Property CommandBars As CommandBars

属性值

一个代表 Microsoft Office Excel 命令栏的 Microsoft.Office.Core.CommandBars 对象。

示例

下面的代码示例使用 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

注解

当工作簿嵌入到另一个应用程序中并由用户通过双击工作簿激活时,将 属性与 Workbook 对象一起使用将返回另一个应用程序中可用的 Excel 命令栏集。 在所有其他时间,将此属性与 Workbook 对象一起使用将 null返回 。 没有编程方式可以返回附加到工作簿的命令栏集。 命令栏与应用程序关联,而不是工作簿。 此属性存在于工作簿上,因此当 Excel 不是应用程序时,可以访问 Excel 应用程序命令栏。

适用于