Skip to main content

How to: Protect a Chart Sheet

You can protect a chart sheet to prevent a user from making changes to chart elements. Use the ChartSheet.Protect method to apply protection to a chart sheet. Specify an optional password that should be entered to unprotect a chart sheet.

The ChartSheetProtection enumeration values enable you to specify chart sheet elements to which protection is applied. This example uses the ChartSheetProtection.Default value indicating that protection is applied to both the chart elements and graphic objects on the chart sheet.

View Example

Dim worksheet As Worksheet = workbook.Worksheets("chartTask1")

' Create a chart sheet containing a pie chart.
Dim chartSheet As ChartSheet = workbook.ChartSheets.Add(ChartType.Pie, worksheet("B2:C7"))

' Protect the chart sheet. Prevent end-users from making changes to chart elements.
If Not chartSheet.IsProtected Then
    chartSheet.Protect("password", ChartSheetProtection.Default)
End If

workbook.ChartSheets.ActiveChartSheet = chartSheet

To remove protection, use the ChartSheet.Unprotect method.