VBA编辑受保护的AND共享工作簿

时间:2015-07-17 10:54:42

标签: excel vba excel-vba

我正在创建一份清单,并且不希望任何人能够编辑任何内容。在相关单元格中双击后,工作表会更新。这一切都有效,我让它在受保护状态下工作,但我无法找到任何有关如何使其在受保护和共享状态下工作的帮助。

我尝试了ActiveSheet.ProtectSharing,但它没有用。

Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
ActiveSheet.UnprotectSharing "H:\Finance\Controls\Checklist\Daily Checklist\" & Format(Now, "yyyy") & "\" & Format(Now, "mm - mmmm yy") & _
    "\" & "Finance Daily Checklist " & Format(Now, "dd mmm") & ".xlsm", "checklist"
'Limit Target count to 1
If Target.Count > 1 Then Exit Sub
'Isolate Target to a specific range
If Intersect(Target, Range("Ckboxes")) Is Nothing Then Exit Sub
'Set Target font to "marlett"
Target.Font.name = "marlett"
'Check value of target

If Target.Value <> "a" Then
    Target.Value = "a"    'Sets target Value = "a"
    Target.Offset(0, 2).Value = Environ("UserName")
    Target.Offset(0, 1).Value = Format(Now, "hh:mm:ss")
    Target.Offset(0, 3).Value = Format(Now, "dd-mm-yyyy")

    Cancel = True
    ActiveSheet.ProtectSharing "H:\Finance\Controls\Checklist\Daily Checklist\" & Format(Now, "yyyy") & "\" & Format(Now, "mm - mmmm yy") & _
    "\" & "Finance Daily Checklist " & Format(Now, "dd mmm") & ".xlsm", "checklist"
    Exit Sub
End If
If Target.Value = "a" Then
    Cancel = True
    ActiveSheet.ProtectSharing "H:\Finance\Controls\Checklist\Daily Checklist\" & Format(Now, "yyyy") & "\" & Format(Now, "mm - mmmm yy") & _
    "\" & "Finance Daily Checklist " & Format(Now, "dd mmm") & ".xlsm", "checklist"
    Exit Sub
End If
End Sub

0 个答案:

没有答案