DocumentBase.Protect(WdProtectionType, Object, Object, Object, Object) 方法

定義

對文件套用其中一種保護類型。

public void Protect (Microsoft.Office.Interop.Word.WdProtectionType type, ref object noReset, ref object password, ref object useIRM, ref object enforceStyleLock);
member this.Protect : Microsoft.Office.Interop.Word.WdProtectionType * obj * obj * obj * obj -> unit
Public Sub Protect (type As WdProtectionType, Optional ByRef noReset As Object, Optional ByRef password As Object, Optional ByRef useIRM As Object, Optional ByRef enforceStyleLock As Object)

參數

type
WdProtectionType

所指定文件的保護類型。 WdProtectionType.

noReset
Object

false 表示將表單欄位重設為預設值。 true 則表示如果文件受到保護,就保留目前的表單欄位值。 如果 Type 不是 wdAllowOnlyFormFields,則會 NoReset 忽略 自變數。

password
Object

移除文件保護所需的密碼。 請參閱下方註解。

useIRM
Object

指定是否使用 Information Rights Management (IRM) 保護文件不受變更影響。

enforceStyleLock
Object

指定是否在受保護文件上強制施行格式化限制。

範例

下列程式代碼範例會 Protect 使用 方法來允許使用者只將批註新增至檔。 若要使用此範例,請從文件層級專案中的 ThisDocument 類別執行它。

private void DocumentProtect(ref object securelyStoredPassword)
{
    this.Protect(Word.WdProtectionType.wdAllowOnlyComments,
        ref missing, ref securelyStoredPassword, ref missing, 
        ref missing);
}
Private Sub DocumentProtect(ByRef securelyStoredPassword As Object)
    Me.Protect(Word.WdProtectionType.wdAllowOnlyComments, _
        Password:=securelyStoredPassword)
End Sub

備註

當檔受到保護時,使用者只能進行有限的變更,例如新增批注、進行修訂或完成表單。 如果您使用此方法時,如果文件已經受到保護,則會擲回例外狀況。

避免在應用程式中使用硬式編碼密碼。 如果程式中需要密碼,請向使用者要求密碼、將密碼儲存在變數中,然後在您的程式代碼中使用變數。

選擇性參數

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

適用於