hanphilong103
Thành viên mới

- Tham gia
- 24/11/11
- Bài viết
- 19
- Được thích
- 0
Em đang cần áp dụng code để không cho sửa khi đã nhập liệu & save file.
Tuy nhiên code này chỉ sử dụng cho 1 sheet. Trường hợp, em muốn sử dụng cho tất cả các file thì làm như thế nào?.
Thanks
Thanks
Tuy nhiên code này chỉ sử dụng cho 1 sheet. Trường hợp, em muốn sử dụng cho tất cả các file thì làm như thế nào?.
Thanks
PHP:
Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean)
StartTime = Time
Application.Calculation = xlCalculationManual
Application.ScreenUpdating = False
Application.DisplayAlerts = False
If ActiveSheet.Name = "Sheet1" Then
On Error Resume Next
'Resume to next line if any error occurs
Dim Cell As Range
With ActiveSheet
'first of all unprotect the entire
'sheet and unlock all cells
.Unprotect Password:="vanman"
.Cells.Locked = False
'Now search for non blank cells
'and lock them and unlock blank cells
For Each Cell In ActiveSheet.UsedRange
i = Cell.Row
j = Cell.Column
If Cell.Value <> "" Then
If Cell.Locked = False Then
Cell.Locked = True
End If
End If
Next Cell
Application.StatusBar = "Processing row " & i & " column " & j
.Protect Password:="vanman"
'Protect with blank password, you can change it
End With
EndTime = Time
TotalTime = Format(EndTime - StartTime, "hh:mm:ss")
Application.Calculate
Application.StatusBar = "Total Time Taken " & TotalTime
Application.Calculation = xlCalculationAutomatic
Application.DisplayAlerts = True
Application.ScreenUpdating = True
Application.StatusBar = False
End If
End Sub
Thanks