AllowEditRange.ChangePassword 方法 (Excel)

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

语法

表达式ChangePassword (密码)

表达 一个代表 AllowEditRange 对象的变量。

参数

名称 必需/可选 数据类型 说明
Password 必需 字符串 新密码。

示例

在此示例中,Microsoft Excel 允许编辑活动工作表上的 A1:A4 范围,通知用户,更改此指定区域的密码,然后通知用户更改。 在运行此代码之前,工作表必须受到保护。

Sub UseChangePassword() 
 
 Dim wksOne As Worksheet 
 Dim strPassword As String 
 
 Set wksOne = Application.ActiveSheet 
 
 ' Establish a range that can allow edits 
 ' on the protected worksheet. 
 
 strPassword = InputBox("Please enter the password for the range") 
 wksOne.Protection.AllowEditRanges.Add _ 
 Title:="Classified", _ 
 Range:=Range("A1:A4"), _ 
 Password:=strPassword 
 
 strPassword = InputBox("Please enter the new password for the range") 
 
 ' Change the password. 
 wksOne.Protection.AllowEditRanges("Classified").ChangePassword _ 
 Password:="strPassword" 
 
 MsgBox "The password for these cells has been changed." 
 
End Sub

支持和反馈

有关于 Office VBA 或本文档的疑问或反馈? 请参阅 Office VBA 支持和反馈,获取有关如何接收支持和提供反馈的指南。