Excel复选框并锁定单元格

时间:2017-08-18 10:14:29

标签: vba

逗人, 我需要一个执行以下操作的代码: 当我勾选一个复选框时,它应该冻结,以便只要输入密码就无法编辑它。

该复选框已连接到单元格,并为此分配了以下宏: 也许这会被添加到现有的宏中?

谢谢

Sub CheckBox_Date_Stamp()

Dim cbx As CheckBox

'Application.Caller returns the name of the CheckBox that called this macro
Set cbx = ActiveSheet.CheckBoxes(Application.Caller)

'.TopLeftCell returns the cell address located at the top left corner of the cbx checkbox
With cbx.TopLeftCell
    'Check the checkbox status (checked or unchecked)
    If cbx.Value = xlOn Then
        ' Checkbox is Checked
        ' User Name and Date-Time
        .Offset(0, 1).Value = Environ("UserName")
        .Offset(0, 2).Value = Now
    Else
        ' Checkbox is unchecked; Clear cell contents?
        .Offset(0, 1).ClearContents
        .Offset(0, 2).ClearContents
    End If
End With

0 个答案:

没有答案