Protection Property

Microsoft Office Web Components Visual Basic

object that contains the protection properties for the specified worksheet. The protection properties are ignored if the Enabled property is set to False.

expression.Protection

expression    Required. An expression that returns a Worksheet object.

Example

This example locks the cells in column B and enables protection for the sheet.

Sub ProtectColumnB()

   ' Unlock all of the cells in the active sheet.
   Spreadsheet1.ActiveSheet.Cells.Locked = False

   ' Lock the cells in column B.
   Spreadsheet1.Columns(2).Locked = True

   ' Protect the locked cells.
   Spreadsheet1.ActiveSheet.Protection.Enabled = True

End Sub