在网上找到了下面的代码,但试后不行,请VBA大师帮忙修改一下,或重新写一个。
SubCommandButton11_Click() '增加公式隐藏和保护
Dim f$, st As Worksheet, wb
Application.DisplayAlerts = False
Application.ScreenUpdating = False
On Error Resume Next
f = Dir(ThisWorkbook.Path &"\*.xls")
Do While f > " "
If f<> ThisWorkbook.Name Then
Set wb = Workbooks.Open(ThisWorkbook.Path & "\" & f)
For Each st In wb.Sheets
With st
st.Unprotect
.Cells.Locked = False
.Cells.SpecialCells(xlCellTypeFormulas,23).Select
Selection.Locked = True
Selection.FormulaHidden = True
.Protect.range("A1").Select '激活A1,选区自动消失
End With
Next st
wb.Close 1
End If
f = Dir
Loop
Application.ScreenUpdating = True
Application.DisplayAlerts = True
End Sub
|