Code:
Private Sub Workbook_Open()
    Dim wks As Worksheet
    For Each wks In ThisWorkbook.Worksheets
        wks.Protect userinterfaceonly:=True
    Next wks
End Sub
While protecting a sheet through code there is a parameter 'UserInterfaceOnly' which if set to True allows any modification on sheet through code only. However, it doesn't allow any direct change in the sheet e.g. if you cannot write anything on the sheet if it is protected with 'UserInterfaceOnly' parameter set to True.

Regards: technicalupload