ChangePassword 方法

       

更改受保护的工作表中可以进行编辑的单元格区域的密码。

expression.ChangePassword(Password)

expression   必需。该表达式返回“应用于”列表中的对象之一。

Password   String 类型,必需。密码名称。

示例

本示例中,Microsoft Excel 允许编辑活动工作表上单元格区域 A1:A4,并通知用户,然后更改指定区域的密码并通知用户所做的更改。

Sub UseChangePassword()

    Dim wksOne As Worksheet

    Set wksOne = Application.ActiveSheet

    ' Establish a range that can allow edits
    ' on the protected worksheet.
    wksOne.Protection.AllowEditRanges.Add _
        Title:="Classified", _
        Range:=Range("A1:A4"), _
        Password:="secret"

    MsgBox "Cells A1 to A4 can be edited on the protected worksheet."

    ' Change the password.
    wksOne.Protection.AllowEditRanges(1).ChangePassword _
        Password:="moresecret"

    MsgBox "The password for these cells has been changed."

End Sub