A SheetProtection object contains sheet level protection properties that control what users can interact with when a worksheet is protected. To access SheetProtection, use Worksheet.SheetProtection.

 public sealed class SheetProtection
Public NotInheritable Class SheetProtection

In a new workbook, AllowSelectLockedCells and AllowSelectUnlockedCells default to true. The rest of the properties default to false.

The SheetProtection properties will only take effect if the worksheet is protected. Worksheets can be protected with Worksheet.Protect(String). If the worksheet is not protected, the values of the properties will persist, but will not have an effect.


          //--- Open existing spreadsheet
          ExcelApplication xla = new ExcelApplication();
          Workbook wb = xla.Open(@"C:\MySpreadsheet.xlsx");

          //--- Get SheetProtection
          SheetProtection protection = wb[0].SheetProtection;

          //--- Set Properties
          protection.AllowFormatCells = true;
          protection.AllowSort = false;

        

          '--- Open existing spreadsheet
          Dim xla As New ExcelApplication()
          Dim wb As Workbook = xla.Open("C:\MySpreadsheet.xlsx")

          '--- Get SheetProtection
          Dim protection As SheetProtection = wb(0).SheetProtection

          '--- Set Properties
          protection.AllowFormatCells = true;
          protection.AllowSort = false;

        

Name

Description

AllowSelectLockedCells

AllowSelectUnlockedCells

AllowFormatCells

AllowFormatRows

AllowFormatColumns

AllowInsertColumns

AllowInsertRows

AllowInsertHyperlinks

AllowDeleteColumns

AllowDeleteRows

AllowSort

AllowUseAutoFilter

AllowUsePivotTableReports