非淡泊无以明志,非宁静无以致远
全部博文(408)
分类: C/C++
2009-11-20 17:05:07
一.Word文档写保护函数:
void _Document::Protect(long Type, VARIANT* NoReset, VARIANT* Password, VARIANT* UseIRM, VARIANT* EnforceStyleLock)
{
static BYTE parms[] =
VTS_I4 VTS_PVARIANT VTS_PVARIANT VTS_PVARIANT VTS_PVARIANT;
InvokeHelper(0x1d3, DISPATCH_METHOD, VT_EMPTY, NULL, parms,
Type, NoReset, Password, UseIRM, EnforceStyleLock);
}
参数说明:
1.Type
Required. The protection type for the specified document.
WdProtectionType includeing as follows:
Members
Member name Description
Allow only comments to be added to the document.
Allow content to be added to the document only through form fields.
wdAllowOnlyReading Allow read-only access to the document.
Allow only revisions to be made to existing content.
Do not apply protection to the document.
2.NoReset
Optional Object. False to reset form fields to their default values. True to retain the current form field values if the specified document is protected. If Type isn't wdAllowOnlyFormFields, the NoReset argument is ignored.
3.Password
Optional Object. The password required to remove protection from the specified document. (See Remarks below.)
4.UseIRM
Optional Object. Specifies whether to use Information Rights Management (IRM) when protecting the document from changes.
5.EnforceStyleLock
Optional Object. Specifies whether formatting restrictions are enforced in a protected document.
二.Word文档解除写保护函数:
void _Document::Unprotect(VARIANT* Password)
{
static BYTE parms[] =
VTS_PVARIANT;
InvokeHelper(0x79, DISPATCH_METHOD, VT_EMPTY, NULL, parms,
Password);
}
参数说明:
1.expression 必需。该表达式返回一个 Document 对象。
2.Password Variant 类型,可选。用于保护文档的口令字符串。口令是区分大小写的。如果用户在使用一篇设置有口令的文档时没有提供正确的口令,就会显示一个对话框,提示用户输入口令。
UnProtect 方法示例
3.示例:
解除对活动文档的保护,并以“Blue”为密码。如果文档有密码,则显示一个对话框提醒用户输入密码。
If ActiveDocument.ProtectionType <> wdNoProtection Then
ActiveDocument.Unprotect Password:="Blue"
End If
4.示例:
解除对活动文档的保护。然后插入文本并对文档进行修订保护。
Set aDoc = ActiveDocument
If aDoc.ProtectionType <> wdNoProtection Then
aDoc.Unprotect
Selection.InsertBefore "department six"
aDoc.Protect Type:=wdAllowOnlyRevisions, Password:="Blue"
End If