WorksheetBase.ProtectionMode Property

Definition

Gets a value that indicates whether user interface-only protection is turned on.

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

Property Value

true if user interface-only protection is turned on; otherwise, false.

Examples

The following code example gets the value of the ProtectionMode property to determine whether the user interface is protected. If the user interface is unprotected, then the Protect method is called with the UserInterfaceOnly parameter set to true so that the user interface is protected.

This example is for a document-level customization.

private void ProtectUserInterface()
{
    if (!this.ProtectionMode)
    {
        if (DialogResult.Yes == MessageBox.Show("User interface protection is " +
            "turned off. Turn on user interface protection?", "Example",
            MessageBoxButtons.YesNo))
        {
            // Enable user interface protection, but do not change 
            // any other protection type.
            this.Protect(this.ProtectDrawingObjects,
                this.ProtectContents, this.ProtectScenarios,
                true, 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 ProtectUserInterface()
    If Not Me.ProtectionMode Then
        If DialogResult.Yes = MessageBox.Show("User interface protection is " & _
            "turned off. Turn on user interface protection?", "Example", _
            MessageBoxButtons.YesNo) Then

            ' Enable user interface protection, but do not change 
            ' any other protection type.
            Me.Protect(DrawingObjects:=Me.ProtectDrawingObjects, _
                Contents:=Me.ProtectContents, Scenarios:=Me.ProtectScenarios, _
                UserInterfaceOnly:=True, _
                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

Remarks

To turn on user interface protection, use the Protect method with the UserInterfaceOnly argument set to true.

Applies to