共用方式為


保護物件 (Excel)

代表工作表上各種可以使用的保護選項。

註解

使用 Worksheet 物件的 Protection 屬性來傳回 Protection 物件。

傳回 保護 物件之後,您可以使用 保護 屬性來設定或傳回保護選項。

範例

下列範例會示範如何使用 Protection 物件的 AllowInsertingColumns 屬性,在最上面一列置入三個數字並保護工作表。 然後,此範例會檢查允許插入資料行的保護設定是否為 False ,並在必要時將其設定為 True。 最後,這個範例會通知使用者插入欄。

Sub SetProtection() 
 
 Range("A1").Formula = "1" 
 Range("B1").Formula = "3" 
 Range("C1").Formula = "4" 
 ActiveSheet.Protect 
 
 ' Check the protection setting of the worksheet and act accordingly. 
 If ActiveSheet.Protection.AllowInsertingColumns = False Then 
 ActiveSheet.Protect AllowInsertingColumns:=True 
 MsgBox "Insert a column between 1 and 3" 
 Else 
 MsgBox "Insert a column between 1 and 3" 
 End If 
 
End Sub

屬性

另請參閱

支援和意見反應

有關於 Office VBA 或這份文件的問題或意見反應嗎? 如需取得支援服務並提供意見反應的相關指導,請參閱 Office VBA 支援與意見反應