示例:添加按钮功能

此示例在用户单击操作名称 Calculator 定义的按钮时,打开计算器。有关添加用户定义按钮的详细信息,请参见将按钮添加到工具栏

将代码添加到 ActionCanExecute 事件过程,这样用户启动操作时就会触发它。

有关 Wscript.Shell 对象的信息,请参考 Microsoft 文档。要访问 VBScript 语言的帮助,请在脚本编辑器中选择帮助 > VBScript 主页

Function ActionCanExecute(ActionName)
        ' Initialize the function's return value to
	 ' avoid unpredictable behavior.
        ActionCanExecute = DefaultRes 
        On Error Resume Next
        If ActionName = "UserDefinedActions.Calculator" Then
            Set shell = CreateObject("Wscript.Shell")
            shell.Run "Calc"
            Set shell = Nothing
        End If
        ActionCanExecute = DefaultRes
        PrintError "ActionCanExecute"
        On Error GoTo 0
End Function