Worksheet.Unprotect Method (2007 System)

Removes protection from the worksheet. This method has no effect if the worksheet is not protected.

Namespace:  Microsoft.Office.Tools.Excel
Assembly:  Microsoft.Office.Tools.Excel.v9.0 (in Microsoft.Office.Tools.Excel.v9.0.dll)

Syntax

'Declaration
Public Sub Unprotect ( _
    Password As Object _
)
'Usage
Dim instance As Worksheet 
Dim Password As Object

instance.Unprotect(Password)
public void Unprotect(
    Object Password
)
public:
void Unprotect(
    Object^ Password
)
public function Unprotect(
    Password : Object
)

Parameters

  • Password
    Type: System.Object

    The case-sensitive password to use to unprotect the worksheet. If the worksheet is not protected with a password, this argument is ignored. If you omit this argument for a worksheet that is protected with a password, you will be prompted for the password.

Remarks

If you forget the password, you cannot unprotect the worksheet. It is a good idea to keep a list of your passwords and their corresponding document names in a safe place.

Optional Parameters

For information on optional parameters, see The Variable missing and Optional Parameters in Office Solutions.

Examples

The following code example determines whether the cell contents of the current worksheet are protected. If the cell contents are protected, then the example prompts the user to unprotect the cell contents by using the Unprotect method.

This example is for a document-level customization.

Private Sub PromptUnprotectWorksheet()
    If Me.ProtectContents Then 
        If DialogResult.Yes = MessageBox.Show("The worksheet is protected. " & _
            "Unprotect the worksheet?", "Example", MessageBoxButtons.YesNo) Then 
            Me.Unprotect()
        End If 
    End If 
End Sub
private void PromptUnprotectWorksheet()
{
    if (this.ProtectContents)
    {
        if (DialogResult.Yes == MessageBox.Show("The worksheet is protected. " +
            "Unprotect the worksheet?", "Example",
            MessageBoxButtons.YesNo))
        {
            this.Unprotect(missing);
        }
    }
}

.NET Framework Security

See Also

Reference

Worksheet Class

Worksheet Members

Microsoft.Office.Tools.Excel Namespace