在beforesave事件中遍歷usedRange,把每個formula不為空的單元格加鎖 Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean) Dim sht As Worksheet, rC As Range For Each sht In Sheets sht.Unprotect With sht For Each rC In .UsedRange If rC.FormulaLocal <> "" Then rC.Locked = True Else rC.Locked = False End If Next End With sht.Protect Next End Sub 附件可參考
在beforesave事件中遍歷usedRange,把每個formula不為空的單元格加鎖 Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean) Dim sht As Worksheet, rC As Range For Each sht In Sheets sht.Unprotect With sht For Each rC In .UsedRange If rC.FormulaLocal <> "" Then rC.Locked = True Else rC.Locked = False End If Next End With sht.Protect Next End Sub 附件可參考