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
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 命名空間