Example: Adding Button Functionality
This example opens a calculator when a user clicks a button defined with action name Calculator
. For details about adding user-defined buttons, see Add toolbar buttons.
Add the code to the ActionCanExecute
event procedure, so that it is triggered when a user initiates an action.
For information about the Wscript.Shell object, refer to the Microsoft documentation. To access help for the VBScript language, choose Help > VBScript Home Page in the Script Editor.
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