Excel VBA:工作表保护图解教程
- 2023-02-17
- 来源/作者: Wps Office教程网/ 菜鸟图库
- 121 次浏览
实例:保护工作表,并禁止选定锁定的单元格,同时允许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