WorkbookBase.CommandBars 属性

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

命名空间:  Microsoft.Office.Tools.Excel
程序集:  Microsoft.Office.Tools.Excel.v4.0.Utilities(在 Microsoft.Office.Tools.Excel.v4.0.Utilities.dll 中)

语法

声明
Public ReadOnly Property CommandBars As CommandBars
    Get
public CommandBars CommandBars { get; }

属性值

类型:Microsoft.Office.Core.CommandBars
Microsoft.Office.Core.CommandBars 对象,表示 Microsoft Office Excel 命令栏。

备注

当某个工作簿嵌入另一个应用程序中,并由用户通过双击该工作簿激活时,通过工作簿对象使用该属性可返回其他应用程序中的可用 Excel 命令栏集。 在其他任何情况下,通过工作簿对象使用该属性都返回 nullnull 引用(在 Visual Basic 中为 Nothing)。 不能以编程方式返回附加到工作簿的命令栏集。 命令栏与应用程序关联,而不与工作簿关联。 此属性存在于工作簿上,因此可以在应用程序不是 Excel 时访问 Excel 应用程序命令栏。

示例

下面的代码示例使用 CommandBars 属性删除所有不可见的自定义命令栏。 此示例假定当前工作簿嵌入在另一个应用程序中。

此示例针对的是文档级自定义项。

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
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.");
    }
}

.NET Framework 安全性

请参见

参考

WorkbookBase 类

Microsoft.Office.Tools.Excel 命名空间