Skip to content
本页内容

ChangePassword (方法)

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

参数

属性数据类型必填说明
Passwordstr必填新密码。

示例

python
#在此示例中,ET 允许编辑活动工作表上的 A1:A4 范围,通知用户更改此指定区域的密码,然后通知用户更改成功。在运行此代码之前,工作表必须未受到保护
def test():
    sheet = Application.ActiveSheet
    sheet.Unprotect()

    # Establish a range that can allow edits on the protected worksheet.
    strPassword = "Please enter the password for the range"
    sheet.Protection.AllowEditRanges.Add("Classified", Range("A1:A4"), strPassword)

    strPassword = "Please enter the new password for the range"

    # Change the password.
    sheet.Protection.AllowEditRanges("Classified").ChangePassword(strPassword)

    print("The password for these cells has been changed.")
python
#本示例将活动工作表上第一个可以进行编辑的区域的密码更改为“Y6dh!et5”
def test():
    ActiveSheet.Protection.AllowEditRanges.Item(1).ChangePassword("Y6dh!et5")