Password Protection on Office Documents

It is possible to set a password on your Microsoft Office Word documents and Microsoft Office Excel workbooks so that they cannot be opened by someone who does not know the password. This option is called Password on Open.

Applies to: The information in this topic applies to document-level projects for the following applications: Excel 2007 and Excel 2010; Word 2007 and Word 2010. For more information, see Features Available by Office Application and Project Type.

You can create document-level projects using existing documents and workbooks that have Password on Open enabled. The behavior in Visual Studio is different for Word and Excel documents that have Password on Open enabled.

For information about enabling Password on Open, see Help in Word or Excel.

Behavior of Excel and Word

Every time you open an Excel workbook in Visual Studio that has Password on Open enabled, Excel prompts you for the password. When you build your solution you will be prompted for the password again, because the document is opened during build.

The first time you open a Word document in Visual Studio that has Password on Open enabled, Word prompts you for the password. After you successfully enter the password, Password on Open is removed from the document and opening the document will no longer require a password. If you want the document in your solution to require a password before it can be opened, you must enable Password on Open after your final build and before you deploy the solution.

See Also

Tasks

How to: Permit Code to Run Behind Documents with Restricted Permissions

Concepts

Document Protection in Document-Level Solutions

Information Rights Management and Managed Code Extensions Overview

Other Resources

Designing and Creating Office Solutions