共用方式為


CommandBars.ActionControl 屬性 (Office)

取得其 OnAction 屬性設為執行的程序的 CommandBarControl 物件。 唯讀。

注意事項

[!注意事項] CommandBars 用於部分的 Microsoft Office 應用程式已經由 Microsoft Office Fluent 使用者介面的新功能區元件取代。 如需詳細資訊,請參閱 Office Fluent 功能區概觀

語法

表達。動作控制

代表 CommandBars 物件的變數。

範例

此範例會建立名為 Custom 的命令列,將三個按鈕新增至其中,然後使用 ActionControl 屬性和 Tag 屬性來判斷上次按一下的命令列按鈕。

Set myBar = CommandBars _ 
    .Add(Name:="Custom", Position:=msoBarTop, _ 
    Temporary:=True) 
Set buttonOne = myBar.Controls.Add(Type:=msoControlButton) 
With buttonOne 
    .FaceId = 133 
    .Tag = "RightArrow" 
    .OnAction = "whichButton" 
End With 
Set buttonTwo = myBar.Controls.Add(Type:=msoControlButton) 
With buttonTwo 
    .FaceId = 134 
    .Tag = "UpArrow" 
    .OnAction = "whichButton" 
End With 
Set buttonThree = myBar.Controls.Add(Type:=msoControlButton) 
With buttonThree 
    .FaceId = 135 
    .Tag = "DownArrow" 
    .OnAction = "whichButton" 
End With 
myBar.Visible = True

下列的副程式回應 OnAction 方法,並決定哪些命令列按鈕上次按下。

Sub whichButton() 
Select Case CommandBars.ActionControl.Tag 
    Case "RightArrow" 
        MsgBox ("Right Arrow button clicked.") 
    Case "UpArrow" 
        MsgBox ("Up Arrow button clicked.") 
    Case "DownArrow" 
        MsgBox ("Down Arrow button clicked.") 
End Select 
End Sub

另請參閱

支援和意見反應

有關於 Office VBA 或這份文件的問題或意見反應嗎? 如需取得支援服務並提供意見反應的相關指導,請參閱 Office VBA 支援與意見反應