Add protection to Worksheet : Worksheet Protection « Excel « VBA / Excel / Access / Word






Add protection to Worksheet

 

Sub Set_Protection()
    On Error GoTo errorHandler
    Dim myDoc As Worksheet
    Dim cel As Range
    Set myDoc = ActiveSheet
    myDoc.Unprotect
    For Each cel In myDoc.UsedRange
        cel.Locked = True
        cel.Font.ColorIndex = xlColorIndexAutomatic
    Next
    myDoc.Protect
    Exit Sub
    errorHandler:
    MsgBox Error
End Sub

 








Related examples in the same category

1.Protect Sheet
2.Unprotect worksheet
3.Show Protection Properties
4.remove user
5.Remove user edit range
6.Add user edit range
7.Formulas Protection
8.Protecting Worksheet Assets with the Protect Method