Product Tour
What's New
Start Now
For Windows For Mac For Linux

Read-Only Office Protection

> Edraw Tip > Read-Only Office Protection
Posted by James Freeman | 12/13/2021
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,

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,


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.


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! You Will Love This Easy-To-Use Diagram Software

EdrawMax is an advanced all-in-one diagramming tool for creating professional flowcharts, org charts, mind maps, network diagrams, UML diagrams, floor plans, electrical diagrams, science illustrations, and more. Just try it, you will love it!