保护工作表公式
Sub LockCellsWithFormulas()
With ActiveSheet
.Unprotect
.Cells.Locked = False
.Cells.SpecialCells(xlCellTypeFormulas).Locked = True
.Protect AllowDeletingRows:=True
End With
End Sub
保护所有工作表里的公式
Sub protect_formulas()
Application.ScreenUpdating = False
Application.DisplayAlerts = False
On Error Resume Next
Dim sht As Worksheet
For Each sht In ThisWorkbook.Sheets
sht.Select
With Cells '解除所有单元格的锁定和隐藏
.Locked = False
.FormulaHidden = False
End With
With Cells.SpecialCells(xlCellTypeFormulas) '对所有使用公式的单元格进行锁定和隐藏
.Locked = True
.FormulaHidden = True
End With
sht.Protect
Next
End Sub
赞 (0)