Read-Only Office Protection - Protect Word document and Excel from unauthorized changes

Office Viewer Component allows developers to protect Word document and Excel 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.

Download Office Viewer Component and View Sample Projects

Protect Method

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 document.
Password: Optional Object. The password required to remove protection from the specified document.

Protect Word Document from Unauthorized Changes

The ProtectionType for the word document can be one of the following values.

enum WdProtectType
{
wdAllowOnlyRevisions = 0,
wdAllowOnlyComments = 1,
wdAllowOnlyFormFields = 2,
wdAllowOnlyReading = 3,
wdNoProtection = -1,
}WdProtectType;

For Example:

The following VBScript shows how to protect a document for limited revisions.

Sub ProtectDoc_Example()
EDOffice.ProtectDoc wdAllowOnlyRevisions
End Sub

You can add the above code at the DocumentOpened event.

Protect Excel

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,
}XlProtectType;

Example

The following VBScript shows how to protect Excel workbook.

Sub ProtectDoc_Example()
EDOffice.ProtectDoc XlProtectTypeNormal|XlProtectTypeWindow|XlProtectTypeStruct
End Sub

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.

Cancel Word and Excel Protection

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.

Example

The following VBScript shows how to unprotect a document with password 832-f2322.

Sub Unprotect_Example()
EDOffice.UnProtectDoc "832-f2322"
End Sub

Disable MS Word Shortcut Hot Key

Disable MS Word Standard Command

Disable Office Ribbon Button

Show/Hide Office Menu Bar

Get Started! Make your application display and interact with MS Office. Try Office Viewer Component
Top