Office Viewer Component allows developers to protect Word and Excel documents from unauthorized changes. You can protect a form to prevent users from making changes as they fill it out. A form contains two types of content: form fields (form field: In a form, a location where a particular type of data, such as a name or address, is stored.), such as check boxes, display content and text that labels a check box or instructions for filling out the form. People can use the form fields to fill out the form, but they should not be able to change the display content. You can allow comments or track changes only for your word document. The protected document can't be modified in text content or the format. The toolbar will be disabled.
Boolean ProtectDoc(long ProtectType, [in, optional] VARIANT Password)
Helps to protect the specified document from changes. When a document is protected, users can make only limited changes, such as adding annotations, making revisions, or completing a form.
ProtectionType: The protection type for the specified
Password: Optional Object. The password required to remove protection from the specified document.
The ProtectionType for the word document can be one of the following values.
wdAllowOnlyRevisions = 0,
wdAllowOnlyComments = 1,
wdAllowOnlyFormFields = 2,
wdAllowOnlyReading = 3,
wdNoProtection = -1,
The following VBScript shows how to protect a document for limited revisions.
You can add the above code at the DocumentOpened event.
Microsoft Excel provides several layers of security and protection to control who can access and change your Excel data. For optimal security, you should protect your entire workbook file with a password, allowing only authorized users to view or modify your data.
For additional protection of specific data, you can protect certain worksheet or workbook elements. Use element protection to help you prevent anyone from accidentally or deliberately changing, moving, or deleting important data.
The ProtectionType for the Excel document can be one of the follow values.
typedef enum XlProtectType
XlProtectTypeNormal = 0x00000001,
XlProtectTypeWindow = 0x00000002,
XlProtectTypeStruct = 0x00000004,
XlProtectTypeDrawingObjects = 0x00000010,
XlProtectTypeContents = 0x00000020,
XlProtectTypeScenarios = 0x00000040,
XlProtectTypeUserInterfaceOnly = 0x00000080,
The following VBScript shows how to protect Excel workbook.
You can lock the structure of a workbook, which prevents users from adding or deleting worksheets or from displaying hidden worksheets. You can also hinder users from changing the size or position of worksheet windows. Workbook structure and window protection applies to the entire workbook.
Boolean UnProtectDoc([in, optional] VARIANT Password);
Removes protection from the specified document. If the
document isn't protected, this method generates an error.
Password: Optional Object. The password is required to remove protection from the specified document.
The following VBScript shows how to unprotect a document with password 832-f2322.