更新:2007 年 11 月
保护工作簿使其无法修改。
命名空间:  Microsoft.Office.Tools.Excel
程序集:  Microsoft.Office.Tools.Excel.v9.0(在 Microsoft.Office.Tools.Excel.v9.0.dll 中)
语法
声明
Public Sub Protect ( _
    Password As Object, _
    Structure As Object, _
    Windows As Object _
)
用法
Dim instance As Workbook
Dim Password As Object
Dim Structure As Object
Dim Windows As Object
instance.Protect(Password, Structure, _
    Windows)
public void Protect(
    Object Password,
    Object Structure,
    Object Windows
)
参数
- Password 
 类型:System.Object- 工作簿的密码,区分大小写。如果省略此参数,则无需使用密码即可取消保护工作簿。否则,必须指定密码才能取消保护工作簿。 
- Structure 
 类型:System.Object- 如果为 true,则保护工作簿的结构(工作表的相对位置)。默认值为 false。 
- Windows 
 类型:System.Object- 如果为 true,则保护工作簿窗口。如果省略此参数,则窗口不受保护。 
备注
使用由大写字母和小写字母、数字和符号组合而成的强密码。弱密码不混合使用这些元素。例如,“Y6dh!et5”是强密码,“House27”是弱密码。使用一个方便记忆的强密码,这样就不必将它记在纸上。
可选参数
有关可选参数的信息,请参见了解 Office 解决方案中的可选参数。
示例
下面的代码示例使用 Protect 方法在不指定密码保护的情况下保护工作簿结构和工作簿窗口。然后,此示例检查 ProtectStructure 和 ProtectWindows 属性的值,验证已设置了此保护。
此示例针对的是文档级自定义项。
Private Sub ProtectWorkbook()
    Me.Protect(Structure:=True, Windows:=True)
    If Me.ProtectStructure Then
        MsgBox("You cannot add, delete or change the location " & _
            "of sheets in this workbook.")
    End If
    If Me.ProtectWindows Then
        MsgBox("You cannot arrange windows in this workbook.")
    End If
End Sub
private void ProtectWorkbook()
{
    this.Protect(missing, true, true);
    if (this.ProtectStructure)
    {
        MessageBox.Show("You cannot add, delete or change the location " +
            "of sheets in this workbook.");
    }
    if (this.ProtectWindows)
    {
        MessageBox.Show("You cannot arrange windows in this workbook.");
    }
}
权限
- 对直接调用方的完全信任。此成员不能由部分信任的代码使用。有关更多信息,请参见通过部分受信任的代码使用库。