Worksheet.Protect 方法 (Excel)
會保護工作表,使其無法進行修改。
語法
運算式。保護 (密碼、 DrawingObjects、 內容、 案例、 UserInterfaceOnly、 AllowFormattingCells、 AllowFormattingColumns、 AllowFormattingRows、 AllowInsertingColumns、 AllowInsertingRows、 AllowInsertingHyperlinks、 AllowDeletingColumns、 AllowDeletingRows、 AllowSorting、 AllowFiltering、 AllowUsingPivotTables)
表達 代表 Worksheet 物件的 變數。
參數
名稱 | 必要/選用 | 資料類型 | 描述 |
---|---|---|---|
Password | 選用 | Variant | 字串,用於指定工作表或活頁簿的密碼,該密碼區分大小寫。 如果省略這個引數,則不需使用密碼就可以取消對該工作表或活頁簿的保護。 否則,必須指定密碼,才能取消對該工作表或活頁簿的保護。 如果忘記密碼,就無法取消對該工作表或活頁簿的保護。 Use strong passwords that combine uppercase and lowercase letters, numbers, and symbols. Weak passwords don't mix these elements. Strong password: Y6dh!et5. Weak password: House27. Passwords should be 8 or more characters in length. A pass phrase that uses 14 or more characters is better. 請務必記住您的密碼。 If you forget your password, Microsoft cannot retrieve it. Store the passwords that you write down in a secure place away from the information that they help protect. |
DrawingObjects | 選用 | Variant | 如果為 True,則會保護圖案。 預設值為 True。 |
Contents | 選用 | Variant | 如果為 True,則會保護內容。 如果是圖表,這樣可保護整張圖表。 如果是工作表,這樣可保護鎖定的儲存格。 預設值為 True。 |
Scenarios | 選用 | Variant | 如果為 True,則會保護分析藍本。 這個引數只適用於工作表。 預設值為 True。 |
UserInterfaceOnly | 選用 | Variant | 如果為 True,則會保護使用者介面,但不會保護巨集。 如果省略這個引數,則會同時保護巨集和使用者介面。 |
AllowFormattingCells | 選用 | Variant | 如果為 True,則允許使用者在受保護的工作表上設定任何儲存格的格式。 預設值為 False。 |
AllowFormattingColumns | 選用 | Variant | 如果為 True,則允許使用者在受保護的工作表上設定任何欄的格式。 預設值為 False。 |
AllowFormattingRows | 選用 | Variant | True 允許使用者格式化受保護工作表上的任何資料列。 預設值為 False。 |
AllowInsertingColumns | 選用 | Variant | 如果為 True,則允許使用者在受保護的工作表上插入欄。 預設值為 False。 |
AllowInsertingRows | 選用 | Variant | 如果為 True,則允許使用者在受保護的工作表上插入列。 預設值為 False。 |
AllowInsertingHyperlinks | 選用 | Variant | True 允許使用者在受保護的工作表上插入超連結。 預設值為 False。 |
AllowDeletingColumns | 選用 | Variant | 如果為 True,則允許使用者在受保護的工作表上刪除欄,而且要刪除的欄中每一個儲存格都已解除鎖定。 預設值為 False。 |
AllowDeletingRows | 選用 | Variant | 如果為 True,則允許使用者在受保護的工作表上刪除列,而且要刪除的列中每一個儲存格都已解除鎖定。 預設值為 False。 |
AllowSorting | 選用 | Variant | 如果為 True,則允許使用者在受保護的工作表上進行排序。 排序範圍中的每一個儲存格都必須已解除鎖定或取消保護。 預設值為 False。 |
AllowFiltering | 選用 | Variant | 如果為 True,則允許使用者在受保護的工作表上設定篩選。 使用者可以變更篩選準則,但是不能啟用或停用自動篩選。 使用者可以在現有的自動篩選上再設定篩選。 預設值為 False。 |
AllowUsingPivotTables | 選用 | Variant | True 允許使用者在受保護的工作表上使用樞紐分析表報表。 預設值為 False。 |
註解
注意事項
在 舊版中,如果您在 UserInterfaceOnly 引數設為 True 的情況下套用此方法,然後儲存活頁簿,則當您重新開啟活頁簿時,整個工作表 (不只是介面) 受到完整保護。 若要在活頁簿開啟後重新啟用使用者介面保護,您必須再次套用此方法,並將 UserInterfaceOnly 設定為 True。
如果您想要變更受保護的工作表,如果提供密碼,可以在受保護的工作表上使用 Protect 方法。 另外一種方法是,先取消對工作表的保護、進行所需的變更,然後再設定對工作表的保護。
注意事項
[未受保護 ] 表示儲存格可能會鎖定 ([ 格式 化儲存格] 對話方塊) ,但包含在 [ 允許使用者編輯範圍 ] 對話方塊中定義的範圍中,而且使用者已使用密碼取消保護範圍,或已透過 NT 許可權進行驗證。
支援和意見反應
有關於 Office VBA 或這份文件的問題或意見反應嗎? 如需取得支援服務並提供意見反應的相關指導,請參閱 Office VBA 支援與意見反應。