在受保护的工作表中添加可编辑的单元格区域。 返回 AllowEditRange 对象。
语法
表达式。添加 (标题、 范围、 密码)
表达 一个代表 AllowEditRanges 对象的变量。
参数
| 名称 | 必需/可选 | 数据类型 | 说明 | 
|---|---|---|---|
| Title | 必需 | 字符串 | 区域的标题。 | 
| 区域 | 必需 | 区域 | Range 对象。 允许编辑的单元格区域。 | 
| Password | 可选 | Variant | 单元格区域的密码。 | 
返回值
一个代表该区域的 AllowEditRange 对象。
示例
此示例允许编辑活动工作表上的 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" 
 ' Protect the worksheet. 
 wksOne.Protect 
 
 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
支持和反馈
有关于 Office VBA 或本文档的疑问或反馈? 请参阅 Office VBA 支持和反馈,获取有关如何接收支持和提供反馈的指南。