ActionControl 属性

       

返回一个 CommandBarControl 对象,该对象的 OnAction 属性设置为当前正在运行的过程。如果当前正在运行的过程不是由命令栏控件初始化的,那么该属性返回 Nothing。只读。

示例

本示例创建命令栏“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

whichButton 子程序响应 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