示例:控制用户权限

此示例演示如何禁止特定用户组的成员执行操作。

仅当用户属于 Admin 用户时,代码才允许用户替换缺陷字段值。

将代码添加到 ActionCanExecute 事件过程,这样用户试图执行操作时将执行检查。

Function ActionCanExecute(ActionName)
        ' Initialize the function's return value
	' to avoid unpredictable behavior.
        ActionCanExecute = False 
        On Error Resume Next
        If ActionName = "UserDefinedActions.BugReplaceAction1" _
            And Not User.IsInGroup("Admin") then
            ActionCanExecute = False
            msgbox "You do not have permission to perform this action"
        Else
            ActionCanExecute = True
        End If
        PrintError "ActionCanExecute"
        On Error GoTo 0
End Function