VBA/Excel/Access/Word/Excel/Workbook Protect
Содержание
checks the UserName; if it is not Admin, this code protects each sheet from user changes
<source lang="vb">
Private Sub Workbook_Open()
Dim sht As Worksheet If Application.UserName <> "Admin" Then For Each sht In Worksheets sht.Protect UserInterfaceOnly:=True Next sht End If
End Sub
</source>
Protect workbook
<source lang="vb">
Sub ProtectWorkbook()
Dim wb As Workbook Set wb = ThisWorkbook wb.Protect "Excel2003", True, True "wb.Unprotect
End Sub
</source>
Show the workbook protection
<source lang="vb">
Sub ShowWbProtection()
Dim wb As Workbook Set wb = ThisWorkbook Debug.Print "Structure protected? " & wb.ProtectStructure, _ "Windows protected? " & wb.ProtectWindows
End Sub
</source>
Unprotect Workbook
<source lang="vb">
Sub UnprotectWorkbook()
Dim wb As Workbook Set wb = ThisWorkbook wb.Unprotect "Excel2003"
End Sub
</source>