ActionControl 属性
优质
小牛编辑
123浏览
2023-12-01
返回一个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