共用方式為


Worksheet.Protect 方法

保護工作表,使工作表無法修改。

命名空間:  Microsoft.Office.Tools.Excel
組件:   Microsoft.Office.Tools.Excel (在 Microsoft.Office.Tools.Excel.dll 中)
  Microsoft.Office.Tools.Excel.v4.0.Utilities (在 Microsoft.Office.Tools.Excel.v4.0.Utilities.dll 中)

語法

'宣告
Sub Protect ( _
    Password As Object, _
    DrawingObjects As Object, _
    Contents As Object, _
    Scenarios As Object, _
    UserInterfaceOnly As Object, _
    AllowFormattingCells As Object, _
    AllowFormattingColumns As Object, _
    AllowFormattingRows As Object, _
    AllowInsertingColumns As Object, _
    AllowInsertingRows As Object, _
    AllowInsertingHyperlinks As Object, _
    AllowDeletingColumns As Object, _
    AllowDeletingRows As Object, _
    AllowSorting As Object, _
    AllowFiltering As Object, _
    AllowUsingPivotTables As Object _
)
void Protect(
    Object Password,
    Object DrawingObjects,
    Object Contents,
    Object Scenarios,
    Object UserInterfaceOnly,
    Object AllowFormattingCells,
    Object AllowFormattingColumns,
    Object AllowFormattingRows,
    Object AllowInsertingColumns,
    Object AllowInsertingRows,
    Object AllowInsertingHyperlinks,
    Object AllowDeletingColumns,
    Object AllowDeletingRows,
    Object AllowSorting,
    Object AllowFiltering,
    Object AllowUsingPivotTables
)

參數

  • Password
    型別:System.Object
    工作表的密碼,區分大小寫。如果省略這個引數,無須使用密碼即可解除工作表的保護。否則,您必須指定密碼才能解除工作表的保護。如果忘記密碼,您將無法解除工作表的保護。建議您最好將密碼清單和密碼的對應文件名稱存放在安全的位置。
  • DrawingObjects
    型別:System.Object
    true 表示會保護圖案。預設值是 false。
  • Contents
    型別:System.Object
    true 表示會保護鎖定儲存格的內容。預設值是 true。
  • Scenarios
    型別:System.Object
    true 表示會保護分析藍本。預設值是 true。
  • UserInterfaceOnly
    型別:System.Object
    true 表示會保護使用者介面,但不保護巨集。如果省略這個引數,則會同時保護巨集和使用者介面。
  • AllowFormattingCells
    型別:System.Object
    true 表示使用者可以對受保護工作表上的任何儲存格設定格式。預設值是 false。
  • AllowFormattingColumns
    型別:System.Object
    true 表示使用者可以對受保護工作表上的任何欄設定格式。預設值是 false。
  • AllowFormattingRows
    型別:System.Object
    true 表示使用者可以對受保護工作表上的任何列設定格式。預設值是 false。
  • AllowInsertingColumns
    型別:System.Object
    true 表示使用者可以在受保護的工作表上插入欄。預設值是 false。
  • AllowInsertingRows
    型別:System.Object
    true 表示使用者可以在受保護的工作表上插入列。預設值是 false。
  • AllowInsertingHyperlinks
    型別:System.Object
    true 表示使用者可以在工作表上插入超連結。預設值是 false。
  • AllowDeletingColumns
    型別:System.Object
    true 表示使用者可以刪除受保護工作表上的欄,不過前提是在要刪除的欄中,每一個儲存格都未被鎖定。預設值是 false。
  • AllowDeletingRows
    型別:System.Object
    true 表示使用者可以刪除受保護工作表上的列,不過前提是在要刪除的列中,每一個儲存格都未被鎖定。預設值是 false。
  • AllowSorting
    型別:System.Object
    true 表示使用者可以在受保護的工作表上排序。排序範圍內的每一個儲存格都必須未被鎖定或保護。預設值是 false。
  • AllowFiltering
    型別:System.Object
    true 表示使用者可以在受保護的工作表上設定篩選條件。使用者可以變更篩選條件,但無法啟用或停用自動篩選條件。使用者可以設定現有自動篩選條件的篩選條件。預設值是 false。
  • AllowUsingPivotTables
    型別:System.Object
    true 表示使用者可以在受保護的工作表上使用樞紐分析表報表。預設值是 false。

備註

如果您套用這個方法並將 UserInterfaceOnly 引數設定為 true 然後儲存活頁簿,則當您再次開啟活頁簿時,整份工作表 (不只是介面) 會被完全保護。 如果要在活頁簿開啟後重新啟用使用者介面保護,您必須再次套用這個方法,並將這個方法的 UserInterfaceOnly 設定為 true。

您可以輸入密碼,變更受到保護的工作表。 此外,您也可以解除工作表的保護、進行必要的變更,然後再設定工作表的保護。

注意事項注意事項

「未被保護」表示儲存格可能是被鎖定的 ([儲存格格式] 對話方塊),但包含在 [允許使用者編輯範圍] 對話方塊中所定義的範圍內,而且使用者是利用密碼解除範圍的保護,或透過 NT 權限進行驗證。

選擇性參數

如需選擇性參數的詳細資訊,請參閱Office 方案中的選擇性參數

.NET Framework 安全性

請參閱

參考

Worksheet 介面

Microsoft.Office.Tools.Excel 命名空間