共用方式為


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 支援與意見反應