Document.Unprotect 方法 (2007 system)

更新:2007 年 11 月

从文档中移除保护功能。

命名空间:  Microsoft.Office.Tools.Word
程序集:  Microsoft.Office.Tools.Word.v9.0(在 Microsoft.Office.Tools.Word.v9.0.dll 中)

语法

声明
Public Sub Unprotect ( _
    ByRef Password As Object _
)
用法
Dim instance As Document
Dim Password As Object

instance.Unprotect(Password)
public void Unprotect(
    ref Object Password
)

参数

  • Password
    类型:System.Object%

    要用来保护文档的密码。密码区分大小写。如果文档是用密码保护的,但是所提供的密码不正确,则会出现一个对话框,提示用户输入密码。

备注

应避免在应用程序中使用硬编码的密码。如果在某个过程中需要使用密码,则向用户请求该密码并将其存储到一个变量中,然后在您的代码中使用该变量。

如果文档不受保护,则将引发异常。

可选参数

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

示例

下面的代码示例使用 Unprotect 方法从文档中移除保护功能。该示例假定密码变量 securelyStoredPassword 是从用户输入获取的。

此示例针对的是文档级自定义项。

Private Sub DocumentUnprotect(ByRef securelyStoredPassword As Object)
    If Me.ProtectionType <> Word.WdProtectionType.wdNoProtection Then
        Me.Unprotect(securelyStoredPassword)
    End If
End Sub
private void DocumentUnprotect(ref object securelyStoredPassword)
{
    if (this.ProtectionType != Word.WdProtectionType.wdNoProtection)
    {
        this.Unprotect(ref securelyStoredPassword);
    }
}

权限

另请参见

参考

Document 类

Document 成员

Microsoft.Office.Tools.Word 命名空间