I added some VBA code to a workbook. code specially doing protect the particular column if the date is less than current date. VBA codes work beautifully when the workbook is not shared.
When I share the workbook, then code will not work in shared mode. Error Msg is showing
"run time error '1004'
Unprotect method of worksheet class faild"
Code what i using below mention.
Private Sub Workbook_Open()
Const PC_ROW_DATE As Integer = 1
Worksheets("Sheet1").Unprotect
Dim lngCol As Long
For lngCol = 2 To Range("A" & PC_ROW_DATE).CurrentRegion.Columns.Count
If Cells(PC_ROW_DATE, lngCol) < Date Then
Columns(lngCol).Locked = 1
Else
Columns(lngCol).Locked = 0
End If
Next lngCol
Worksheets("Sheet1").Protect
End Sub
I just can't figure out why code doesn't work? please provide the help.
Bookmarks