Excel VBA:工作表保护图解教程

实例:保护工作表,并禁止选定锁定的单元格,同时允许VBA在后台对工作表中被保护的单元格进行修改,而不弹出对话框。当blnEnabledIt=0时解除工作表保护。代码如下:

Sub ProtectIt(Optional blnEnabledIt As Boolean = True)
‘ blnEnabledIt = False
With ActiveSheet
If blnEnabledIt Then
.EnableSelection = xlUnlockedCells
.Protect Contents:=True, UserInterfaceOnly:=True
Else
.EnableSelection = xlNoRestrictions
.Unprotect
End If
End With
End Sub

office办公软件入门基础教程 » Excel VBA:工作表保护图解教程