WorkbookBase.Unprotect(Object) 方法

定义

从工作簿中移除保护。 如果工作簿不受保护,则此方法无效。

public void Unprotect (object password);

参数

password
Object

用于取消保护工作簿的密码,区分大小写。 如果工作簿未使用密码保护,则忽略此参数。 如果对使用密码保护的工作簿省略了此参数,则该方法会失败。

示例

下面的代码示例使用 Protect 方法来保护工作簿和工作簿窗口的结构,但不指定密码保护。 然后,该示例通过使用方法提示用户取消保护工作簿 Unprotect

此示例适用于文档级自定义项。

private void WorkbookUnprotect()
{
    MessageBox.Show("Protecting the workbook.");
    this.Protect( true, true);

    if (DialogResult.Yes == MessageBox.Show("Unprotect the workbook?",
        "Custom Unprotect Dialog", MessageBoxButtons.YesNo))
    {
        this.Unprotect();
    }
}
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

注解

如果忘记了密码,则无法取消对工作簿的保护。 最好将密码及其对应文档名的列表保存在安全的位置。

可选参数

有关可选参数的信息,请参阅Office 解决方案中的可选参数

适用于