pradyuthal
Board Regular
- Joined
- Jul 13, 2005
- Messages
- 212
I have the following Vb code with which I can suceesfully protect and unprotect formula cells. I want to get the unprotected formula cells ( with the help of unprotect vb code ) protected automatically whenever i close the excel file.
EDIT:
Added Code tags - Smitty
Code:
Sub lock_formulas()
'Erik Van Geit
'060914
Dim SH As Worksheet
Dim rng As Range
On Error Resume Next
For Each SH In Worksheets
SH.Unprotect
With SH.UsedRange
.Locked = False
Set rng = Nothing
Set rng = .SpecialCells(xlCellTypeFormulas)
If Not rng Is Nothing Then rng.Locked = True
End With
SH.Protect
Next SH
End Sub
Code:
Sub unlock_formulas()
'Erik Van Geit
'060914
Dim SH As Worksheet
Dim rng As Range
On Error Resume Next
For Each SH In Worksheets
SH.Unprotect
With SH.UsedRange
.Locked = False
Set rng = Nothing
Set rng = .SpecialCells(xlCellTypeFormulas)
If Not rng Is Nothing Then rng.Locked = False
End With
SH.Unprotect
Next SH
End Sub
EDIT:
The mind of an Excel-lover is full of structure. It loves reading code which is indented: analysing is quicker: so every effort can go to the problem itself...
Added Code tags - Smitty