0
Private Sub CheckBox9_Click()
    If CheckBox9.Value = True Then
        CheckBox9.Caption = "Done"
        ActiveWorkbook.Sheets("Well Planning Checklist").Tab.ColorIndex = 4
        'ActiveSheet.Tab.ColorIndex = 22
        Range("Q17").Value = CheckBox9.Caption
    Else
        If LCase(Range("Q17").Value) = CheckBox9.Caption Then
            CheckBox9.Value = Not (CheckBox9.Value)
        Else
            CheckBox9.Value = Not (CheckBox9.Value)
        End If
    End If
End Sub

我用上面的方法来确保一旦用户点击复选框,他就不能取消选中它。但是,我希望能够拥有一个我的用户可以重置的 Button 。一切,而不仅仅是复选框。我有以下但它不工作。有人可以帮我让它工作吗?

Private Sub CommandButton1_Click()
    CheckBox9

    ActiveWorkbook.Sheets("Well Design Section").CheckBox9.Caption = "Incomplete "
    ActiveWorkbook.Sheets("Well Design Section").CheckBox9.Value = False
    Range("Q17").Value = "Incomplete"
End Sub
4

1 回答 1

2

要解决此问题,您可以将 CheckBox9_Click 子替换为:

Private Sub CheckBox9_Click()
    If CheckBox9.Value = True Then
        CheckBox9.Caption = "Done"
        ActiveWorkbook.Sheets("Well Planning Checklist").Tab.ColorIndex = 4
        'ActiveSheet.Tab.ColorIndex = 22
        Range("Q17").Value = CheckBox9.Caption
    Elseif Checkbox9.Caption <> "Incomplete" Then
        If LCase(Range("Q17").Value) = CheckBox9.Caption Then
            CheckBox9.Value = Not (CheckBox9.Value)
        Else
            CheckBox9.Value = Not (CheckBox9.Value)
        End If
    End If
End Sub

唯一的区别是您的Else语句被替换为Elseif. 它现在只会在Caption <> "Incomplete",which 很好的情况下才会发生,因为如果单击复选框,初始 if 将为 true。

于 2012-10-03T15:35:04.017 回答