Compartir a través de


WorksheetBase.ProtectScenarios Property

Definition

Gets a value that indicates whether worksheet scenarios are protected.

public:
 property bool ProtectScenarios { bool get(); };
public bool ProtectScenarios { get; }
member this.ProtectScenarios : bool
Public ReadOnly Property ProtectScenarios As Boolean

Property Value

true if the worksheet scenarios are protected; otherwise, false.

Examples

The following code example gets the value of the ProtectScenarios property to determine whether worksheet scenarios are protected. If scenarios are unprotected, then the Protect method is called with the Scenarios parameter set to true so that scenarios are protected.

This example is for a document-level customization.

private void SetScenarioProtectionOn()
{
    if (!this.ProtectScenarios)
    {
        if (DialogResult.Yes == MessageBox.Show("Scenario protection is " +
            "turned off. Turn on scenario protection?", "Example",
            MessageBoxButtons.YesNo))
        {
            // Enable scenario protection, but do not change 
            // any other protection type.
            this.Protect(this.ProtectDrawingObjects,
                this.ProtectContents, true, this.ProtectionMode, 
                this.Protection.AllowFormattingCells,
                this.Protection.AllowFormattingColumns,
                this.Protection.AllowFormattingRows,
                this.Protection.AllowInsertingColumns,
                this.Protection.AllowInsertingRows,
                this.Protection.AllowInsertingHyperlinks,
                this.Protection.AllowDeletingColumns,
                this.Protection.AllowDeletingRows,
                this.Protection.AllowSorting,
                this.Protection.AllowFiltering,
                this.Protection.AllowUsingPivotTables);
        }
    }
}
Private Sub SetScenarioProtectionOn()
    If Not Me.ProtectScenarios Then
        If DialogResult.Yes = MessageBox.Show("Scenario protection is " & _
            "turned off. Turn on scenario protection?", "Example", _
            MessageBoxButtons.YesNo) Then

            ' Enable scenario protection, but do not change 
            ' any other protection type.
            Me.Protect(DrawingObjects:=Me.ProtectDrawingObjects, _
                Contents:=Me.ProtectContents, Scenarios:=True, _
                UserInterfaceOnly:=Me.ProtectionMode, _
                AllowFormattingCells:=Me.Protection.AllowFormattingCells, _
                AllowFormattingColumns:=Me.Protection.AllowFormattingColumns, _
                AllowFormattingRows:=Me.Protection.AllowFormattingRows, _
                AllowInsertingColumns:=Me.Protection.AllowInsertingColumns, _
                AllowInsertingRows:=Me.Protection.AllowInsertingRows, _
                AllowInsertingHyperlinks:=Me.Protection.AllowInsertingHyperlinks, _
                AllowDeletingColumns:=Me.Protection.AllowDeletingColumns, _
                AllowDeletingRows:=Me.Protection.AllowDeletingRows, _
                AllowSorting:=Me.Protection.AllowSorting, _
                AllowFiltering:=Me.Protection.AllowFiltering, _
                AllowUsingPivotTables:=Me.Protection.AllowUsingPivotTables)
        End If
    End If
End Sub

Applies to