复选框宏以限制编辑

时间:2017-01-15 21:00:24

标签: excel debugging checkbox

以下代码仅允许授权人(网络名称" JSMITH")勾选我的复选框,以便确认她对发送的报告感到满意(多个报告用户)但只有一个授权人)。但我一直收到错误"对象需要"。我在下面的代码中做错了什么?感谢

Private Sub CheckBox1_Click()

    If Environ("username") <> "JSMITH" Then
        CheckBox1.Value = False
    End If

End Sub

1 个答案:

答案 0 :(得分:0)

我认为你所追求的是以下代码:

Sub CheckBox1_Click()
    If ActiveSheet.Shapes("Check Box 1").ControlFormat.Value = 1 Then
        If Environ("username") = "JSMITH" or Environ("username") = "DTailor" Then
        'Do nothing
        Else
        'Uncheck because user not matching
        ActiveSheet.Shapes("Check Box 1").ControlFormat.Value = 0
        MsgBox ("You are not authorized to tick this box.")
        End If
    End If

End Sub

对于ActiveX复选框,我将使用以下代码:

Sub CheckBox1_Click()
    If ActiveSheet.OLEObjects("CheckBox1").Object.Enabled = True Then
        If Environ("username") = "JSMITH" or Environ("username") = "DTailor" Then
        'Do nothing
        Else
        'Uncheck because user not matching
        ActiveSheet.OLEObjects("CheckBox1").Object.Enabled = False
        MsgBox ("You are not authorized to tick this box.")
        End If
    End If

End Sub
相关问题