VBA/Excel/Access/Word/Excel/Workbook Protect — различия между версиями
Admin (обсуждение | вклад) м (1 версия) |
Admin (обсуждение | вклад) м (1 версия) |
(нет различий)
|
Текущая версия на 12:47, 26 мая 2010
Содержание
checks the UserName; if it is not Admin, this code protects each sheet from user changes
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
Protect workbook
Sub ProtectWorkbook()
Dim wb As Workbook
Set wb = ThisWorkbook
wb.Protect "Excel2003", True, True
"wb.Unprotect
End Sub
Show the workbook protection
Sub ShowWbProtection()
Dim wb As Workbook
Set wb = ThisWorkbook
Debug.Print "Structure protected? " & wb.ProtectStructure, _
"Windows protected? " & wb.ProtectWindows
End Sub
Unprotect Workbook
Sub UnprotectWorkbook()
Dim wb As Workbook
Set wb = ThisWorkbook
wb.Unprotect "Excel2003"
End Sub