Locked Property

Microsoft Office Web Components Visual Basic

True if all cells in the specified range are locked, False if none of the cells are locked, and Null if some cells are locked and some are not. The default value is True. Use the IsNull function to determine whether the return value is Null. Read/write Variant.

expression.Locked

expression    Required. An expression that returns a Range object.

Example

This example locks only the cells in column B on the active sheet in Spreadsheet1 and then protects the worksheet.

Sub LockColumnB()
    Dim shtCurrent
    
    Set shtCurrent = Spreadsheet1.ActiveSheet
    
    ' Clear the locked attribute for all cells on the active sheet.
    shtCurrent.Cells.Locked = False
    
    ' Lock all of the cells in Column B.
    shtCurrent.Columns(2).Locked = True
    
    ' Enable protection on the active sheet.
    shtCurrent.Protection.Enabled = True
End Sub