📜  excel vba 使用公式保护单元格 - VBA 代码示例

📅  最后修改于: 2022-03-11 14:51:53.805000             🧑  作者: Mango

代码示例2
' Protects cells containing formulas, with password
' pPwd: password to protect / unprotect
Sub ProtectFormulas(ByRef pRange As Range, ByVal pPwd As String)
    ActiveSheet.Unprotect pPwd
    For Each r In pRange
        r.Locked = IIf(r.HasFormula, True, False)
    Next r
    ActiveSheet.Protect pPwd
End Sub

Sub TestIt()
    ProtectFormulas Range("A1:B4"), "MyPassWord"
End Sub