Click 事件、CommandButton 控件、加速器、Caption 属性示例
本示例在用户每次使用鼠标或快捷键单击按钮时更改 CommandButton 的 Accelerator 和 Caption 属性。 Click 事件包含用于更改 Accelerator 和 Caption 属性的代码。
To try this example, paste the code into the Declarations section of a form containing a CommandButton named CommandButton1.
Private Sub UserForm_Initialize()
CommandButton1.Accelerator = "C"
'Set Accelerator key to COMMAND + C
End Sub
Private Sub CommandButton1_Click ()
If CommandButton1.Caption = "OK" Then
'Check caption, then change it.
CommandButton1.Caption = "Clicked"
CommandButton1.Accelerator = "C"
'Set Accelerator key to COMMAND + C
Else
CommandButton1.Caption = "OK"
CommandButton1.Accelerator = "O"
'Set Accelerator key to COMMAND + O
End If
End Sub
支持和反馈
有关于 Office VBA 或本文档的疑问或反馈? 请参阅 Office VBA 支持和反馈,获取有关如何接收支持和提供反馈的指南。