Workbook.Unprotect Method (2007 System)

Removes protection from the workbook. This method has no effect if the workbook 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 Workbook 
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 workbook. If the workbook is not protected with a password, this parameter is ignored. If you omit this parameter for a workbook that is protected with a password, the method fails.

Remarks

If you forget the password, you cannot unprotect the workbook. 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 uses the Protect method to protect the structure of the workbook and workbook windows, but without specifying password protection. The example then prompts the user to unprotect the workbook by using the Unprotect method.

This example is for a document-level customization.

Private Sub WorkbookUnprotect()
    MsgBox("Protecting the workbook.")
    Me.Protect(Structure:=True, Windows:=True)

    If DialogResult.Yes = MessageBox.Show( _
        "Unprotect the workbook?", "Custom Unprotect Dialog", _
        MessageBoxButtons.YesNo) Then 
        Me.Unprotect()
    End If 
End Sub
private void WorkbookUnprotect()
{
    MessageBox.Show("Protecting the workbook.");
    this.Protect(missing, true, true);

    if (DialogResult.Yes == MessageBox.Show("Unprotect the workbook?",
        "Custom Unprotect Dialog", MessageBoxButtons.YesNo))
    {
        this.Unprotect(missing);
    }
}

.NET Framework Security

See Also

Reference

Workbook Class

Workbook Members

Microsoft.Office.Tools.Excel Namespace