AllowEditRange.ChangePassword method (Excel)

Changes the password for a range that can be edited on a protected worksheet.

Syntax

expression.ChangePassword (Password)

expression A variable that represents an AllowEditRange object.

Parameters

Name Required/Optional Data type Description
Password Required String The new password.

Example

In this example, Microsoft Excel allows edits to range A1:A4 on the active worksheet, notifies the user, changes the password for this specified range, and then notifies the user of the change. The worksheet must be unprotected before running this code.

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

Support and feedback

Have questions or feedback about Office VBA or this documentation? Please see Office VBA support and feedback for guidance about the ways you can receive support and provide feedback.