Excel VBA protect structure code example
Example 1: excel vba protect sheet
'Apply worksheet protection to contents, objects and scenarios
Sheets("Sheet1").Protect Password:="myPassword", _
DrawingObjects:=True, _
Contents:=True, _
Scenarios:=True
Example 2: excel vba protect content
'Apply protection on worksheet content (cells with Protected = True)
Sheets("Sheet1").Protect Password:="myPassword", _
DrawingObjects:=False, _
Contents:=True, _
Scenarios:=False